GithubHelp home page GithubHelp logo

create-go-app / fiber-go-template Goto Github PK

View Code? Open in Web Editor NEW
832.0 10.0 113.0 688 KB

📝 Production-ready backend template with Fiber Go Web Framework for Create Go App CLI.

Home Page: https://github.com/create-go-app/cli/wiki

License: Apache License 2.0

Dockerfile 1.19% Go 95.65% Makefile 3.17%
template-project golang-app-server golang api-server api-test create-go-app cgapp fiber backend-template docker

fiber-go-template's Introduction

Fiber backend template for Create Go App CLI

go version go report license

Fiber is an Express.js inspired web framework build on top of Fasthttp, the fastest HTTP engine for Go. Designed to ease things up for fast development with zero memory allocation and performance in mind.

⚡️ Quick start

  1. Create a new project with Fiber:
cgapp create

# Choose a backend framework:
#   net/http
# > fiber
#   chi
  1. Rename .env.example to .env and fill it with your environment values.

  2. Install Docker and the following useful Go tools to your system:

  3. Run project by this command:

make docker.run
  1. Go to API Docs page (Swagger): 127.0.0.1:5000/swagger/index.html

Screenshot

🗄 Template structure

./app

Folder with business logic only. This directory doesn't care about what database driver you're using or which caching solution your choose or any third-party things.

  • ./app/controllers folder for functional controllers (used in routes)
  • ./app/models folder for describe business models and methods of your project
  • ./app/queries folder for describe queries for models of your project

./docs

Folder with API Documentation. This directory contains config files for auto-generated API Docs by Swagger.

./pkg

Folder with project-specific functionality. This directory contains all the project-specific code tailored only for your business use case, like configs, middleware, routes or utils.

  • ./pkg/configs folder for configuration functions
  • ./pkg/middleware folder for add middleware (Fiber built-in and yours)
  • ./pkg/repository folder for describe const of your project
  • ./pkg/routes folder for describe routes of your project
  • ./pkg/utils folder with utility functions (server starter, error checker, etc)

./platform

Folder with platform-level logic. This directory contains all the platform-level logic that will build up the actual project, like setting up the database or cache server instance and storing migrations.

  • ./platform/cache folder with in-memory cache setup functions (by default, Redis)
  • ./platform/database folder with database setup functions (by default, PostgreSQL)
  • ./platform/migrations folder with migration files (used with golang-migrate/migrate tool)

⚙️ Configuration

# .env

# Stage status to start server:
#   - "dev", for start server without graceful shutdown
#   - "prod", for start server with graceful shutdown
STAGE_STATUS="dev"

# Server settings:
SERVER_HOST="0.0.0.0"
SERVER_PORT=5000
SERVER_READ_TIMEOUT=60

# JWT settings:
JWT_SECRET_KEY="secret"
JWT_SECRET_KEY_EXPIRE_MINUTES_COUNT=15
JWT_REFRESH_KEY="refresh"
JWT_REFRESH_KEY_EXPIRE_HOURS_COUNT=720

# Database settings:
DB_TYPE="pgx"   # pgx or mysql
DB_HOST="cgapp-postgres"
DB_PORT=5432
DB_USER="postgres"
DB_PASSWORD="password"
DB_NAME="postgres"
DB_SSL_MODE="disable"
DB_MAX_CONNECTIONS=100
DB_MAX_IDLE_CONNECTIONS=10
DB_MAX_LIFETIME_CONNECTIONS=2

# Redis settings:
REDIS_HOST="cgapp-redis"
REDIS_PORT=6379
REDIS_PASSWORD=""
REDIS_DB_NUMBER=0

⚠️ License

Apache 2.0 © Vic Shóstak & True web artisans.

fiber-go-template's People

Contributors

bipy avatar boskiv avatar dependabot-preview[bot] avatar dependabot[bot] avatar eeap avatar feber avatar gaby avatar jamesmura avatar jniltinho avatar koddr avatar p3nj avatar rafaelpiloto10 avatar y-yagi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fiber-go-template's Issues

Wrong key for claims

Required check list:

  • I'm gonna mark the checkboxes like this.
  • I didn't find in the repository's issues section similar bug.
  • I understand, this is Open Source and not-for-profit product.
  • This is not about third-party project, framework, package or technology.

Describe the bug:

claims["expires"] needs to be claims["exp"] in order for the jwt_middleware to properly determine if the token has expired

os.Interrupt does not respond to Ctrl+C after fiber get some requests

Required check list:

  • I'm gonna mark the checkboxes like this.
  • I didn't find in the repository's issues section similar bug.
  • I understand, this is Open Source and not-for-profit product.
  • This is not about third-party project, framework, package or technology.

My environment:

  • OS (uname -a): Darwin us2-al-004.local 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 x86_64 (macOS Monterey 12.0.1 (21A559))
  • Golang (go version): go version go1.17.2 darwin/amd64

Describe the bug:

Steps to reproduce the behavior:

  1. Run App with StartServerWithGracefulShutdown
  2. Get few requests
  3. Press Ctrl+C
  4. App does not exit

Expected behavior:

App should respond to Ctrl+C

Screenshots:
Screen Shot 2021-11-24 at 11 52 00

Additional context:
If I run Ctrl+C before any requests are served, it works as expected
Screen Shot 2021-11-24 at 11 52 21

go version error in Dockerfile

Required check list:

  • I'm gonna mark the checkboxes like this.
  • I didn't find in the repository's issues section similar bug.
  • I understand, this is Open Source and not-for-profit product.
  • This is not about third-party project, framework, package or technology.

My environment:

  • OS (uname -a): Darwin Kernel Version 22.5.0
  • Golang (go version): go1.20.3 darwin/arm64

Describe the bug:
github.com/rivo/uniseg v0.4.4 // indirect module needs go1.18+, so error occurs about go version in Dockerfile when I enter make docker.run command for build.

Steps to reproduce the behavior:

Expected behavior:

Screenshots:

image

Additional context:

docker "network dev-network not found"

By following the readme in the backend directory, I ran make docker.postgres to run pgsql db in docker, but it gave me an error network dev-network not found
When I checked in the Makefile, I found that it was attaching it to the network dev-network meaning that I had to first create docker network named dev-network

So, after running docker network create dev-network when I ran the make command again, it was fine.

I think it's best to include this as a command in makefile like as well as mention this before running docker.fiber or docker.postgres

DEV_NET_EXISTS=`docker network ls -f name=dev-network -q | wc -l`
docker.network:
	@if [ $(DEV_NET_EXISTS) -eq 0 ]; then docker network create dev-network; fi

GetBooks returns empty

I changed the method of sqlx to get all book in backend/app/queries/book_query.go:
err := q.Select(&books, "SELECT * FROM books")

Now, it's working!

Swagger docs broken

Required check list:

  • I'm gonna mark the checkboxes like this.
  • I didn't find in the repository's issues section similar bug.
  • I understand, this is Open Source and not-for-profit product.
  • This is not about third-party project, framework, package or technology.

My environment:

  • OS (uname -a): Windows 11 Home 22H2 22621.2134
  • Golang (go version): go version go1.21.0 windows/amd64

Describe the bug:

Automatically generated Swagger 2 docs don't work. /v1/user/sign/up endpoint doesn't send JSON encoded payload but rather the raw value of user_role.

Steps to reproduce the behavior:

  1. Go to /swagger/index.html#/User/post_v1_user_sign_up
  2. Click on 'Try it out'
  3. Fill values
  4. Click on 'execute'
  5. See error

Expected behavior:

Swagger should send a JSON encoded payload including all fields.

Screenshots:
Captura de pantalla 2023-09-07 162011

Additional context:

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

github.com/create-go-app/fiber-go-template/docs: cannot find module providing package github.com/create-go-app/fiber-go-template/docs
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/configs: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/configs
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/middleware: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/middleware
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/routes: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/routes
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/utils: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/utils

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

zsh: killed cgapp create

Required check list:

  • I'm gonna mark the checkboxes like this.
  • I didn't find in the repository's issues section similar bug.
  • I understand, this is Open Source and not-for-profit product.
  • This is not about third-party project, framework, package or technology.

My environment:

  • OS (Mac OS):
  • Golang (go1.18.3 darwin/arm64):

Describe the bug:

I get this error when I use this command 'cgapp create'
The error is : zsh: killed cgapp create.

I used brew to install this package.

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

github.com/create-go-app/fiber-go-template/docs: cannot find module providing package github.com/create-go-app/fiber-go-template/docs
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/configs: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/configs
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/middleware: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/middleware
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/routes: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/routes
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/utils: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/utils

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

github.com/create-go-app/fiber-go-template/docs: cannot find module providing package github.com/create-go-app/fiber-go-template/docs
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/configs: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/configs
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/middleware: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/middleware
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/routes: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/routes
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/utils: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/utils

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

github.com/create-go-app/fiber-go-template/docs: cannot find module providing package github.com/create-go-app/fiber-go-template/docs
	github.com/create-go-app/fiber-go-template/pkg/configs: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/configs
	github.com/create-go-app/fiber-go-template/pkg/middleware: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/middleware
	github.com/create-go-app/fiber-go-template/pkg/routes: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/routes
	github.com/create-go-app/fiber-go-template/pkg/utils: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/utils

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

`swag init` breaks `make critic`

Required check list:

  • I'm gonna mark the checkboxes like this.
  • I didn't find in the repository's issues section similar bug.
  • I understand, this is Open Source and not-for-profit product.
  • This is not about third-party project, framework, package or technology.

My environment:

  • OS (uname -a): Darwin Maccie.local 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:29 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T8101 arm64
  • Golang (go version): go version go1.18.2 darwin/arm64

Describe the bug:

swag init will break make critic

  1. first time $ make critic have no error output
  2. use $ swag init regenerate swag documents, include docs.go
  3. run $ make critic again.
  4. See output
./docs/docs.go:2:1: codegenComment: comment should match `Code generated .* DO NOT EDIT.` regexp
make: *** [critic] Error 1

Expected behavior:

$ make critic should exit without issue after $ swag init

Screenshots:
t-rec

Additional context:

$ swag init also won't read the @BasePath defines inside main.go.
Will have to manually add /api to all API endpoints in order to make Swagger UI work.

Error starting app

fe1abc5015f9e2fcb4715b1a639d1e7c0f290e31e6b80cd83833bce80198a
make: *** No rule to make target swag.init', needed by docker.run'. Stop.

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

github.com/create-go-app/fiber-go-template/docs: cannot find module providing package github.com/create-go-app/fiber-go-template/docs
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/configs: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/configs
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/middleware: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/middleware
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/routes: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/routes
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/utils: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/utils

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

errSaveToRedis Causes Panic

Required check list:

  • I didn't find in the repository's issues section similar bug.
  • I understand, this is Open Source and not-for-profit product.
  • This is not about third-party project, framework, package or technology.

My environment:

  • OS (uname -a): Darwin poisson.local 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:47:26 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T8101 arm64
  • Golang (go version): go version go1.18.1 darwin/amd64

Describe the bug:

Incorrect redis error handling leads to panic when Redis Save throws error.

Steps to reproduce the behavior:

Do not install Redis and try to sign in

Expected behavior:

Error handling should catch errSaveToRedis and return error. Should look like:

// Save refresh token to Redis.
errSaveToRedis := connRedis.Set(context.Background(), userID, tokens.Refresh, 0).Err()
if errSaveToRedis != nil {
// Return status 500 and Redis connection error.
  return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
	  "error": true,
	  "msg":   errSaveToRedis.Error(),
  })
}

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

github.com/create-go-app/fiber-go-template/docs: cannot find module providing package github.com/create-go-app/fiber-go-template/docs
	github.com/create-go-app/fiber-go-template/pkg/configs: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/configs
	github.com/create-go-app/fiber-go-template/pkg/middleware: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/middleware
	github.com/create-go-app/fiber-go-template/pkg/routes: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/routes
	github.com/create-go-app/fiber-go-template/pkg/utils: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/utils

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Running make test results in failure

Required check list:

  • I'm gonna mark the checkboxes like this.
  • I didn't find in the repository's issues section similar bug.
  • I understand, this is Open Source and not-for-profit product.
  • This is not about third-party project, framework, package or technology.

My environment:

  • OS (uname -a): Darwin Kernel Version 22.1.0
  • Golang (go version): go version go1.20.2 darwin/arm64

Describe the bug:

Running make test results in the following error:

=== RUN   TestPrivateRoutes
    private_routes_test.go:108: 
                Error Trace:    /Users/xxx/src/xxx/xxx/pkg/routes/private_routes_test.go:108
                Error:          Not equal: 
                                expected: 404
                                actual  : 500
                Test:           TestPrivateRoutes
                Messages:       delete book with credentials
--- FAIL: TestPrivateRoutes (0.03s)
=== RUN   TestPublicRoutes
    public_routes_test.go:65: 
                Error Trace:    /Users/xxx/src/xxx/xxx/pkg/routes/public_routes_test.go:65
                Error:          Not equal: 
                                expected: 404
                                actual  : 500
                Test:           TestPublicRoutes
                Messages:       get book by ID
--- FAIL: TestPublicRoutes (0.00s)
FAIL
        github.com/xxx/xxx/pkg/routes     coverage: 73.3% of statements
FAIL    github.com/xxx/xxx/pkg/routes     0.535s
FAIL
make: *** [test] Error 1

Steps to reproduce the behavior:

  1. Clone the repo
  2. Install dependencies
  3. Run make test
  4. See error

Expected behavior:

No errors are expected from out-of-the-box.

Additional context:

The following error is returned from the request response body:

{
  "error": true,
  "msg": "error, not connected to database, failed to connect to `host=host.docker.internal user=postgres database=postgres`: hostname resolving error (lookup host.docker.internal: no such host)"
}

replace *fiber.App with fiber.Router Interface

Required check list:

  • I'm gonna mark the checkboxes like this.
  • I didn't find in the repository's issues section similar bug.
  • I understand, this is Open Source and not-for-profit product.
  • This is not about third-party project, framework, package or technology.

Is your feature request related to a problem? Please describe.

image
it was like you have default paramente is *fiber.App which is not flexible when we need to change or group some api.
i suggest that you can replace with fiber.Router
image
then we can easilier to group it in main file.

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

github.com/create-go-app/fiber-go-template/docs: cannot find module providing package github.com/create-go-app/fiber-go-template/docs
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/configs: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/configs
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/middleware: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/middleware
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/routes: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/routes
github.com/create-go-app/fiber-go-template imports
	github.com/create-go-app/fiber-go-template/pkg/utils: cannot find module providing package github.com/create-go-app/fiber-go-template/pkg/utils

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.