You can see the whole versions in release page.
VERSION=<version-id> # ex: VERSION=2.X.X
curl -L https://github.com/chan-jui-huang/go-backend-framework/archive/refs/tags/v$VERSION.tar.gz | tar -zxv --strip-components=1 go-backend-framework-$VERSION/gbf-installer.sh
./gbf-installer.sh
# Compile go-backend-framework tool kit
cd <project-name> && make
- mysql
- sqlite (to run test case)
- fill the db environment variable in [.env] file
- make mysql-migration args=up
- execute the [./bin/database_seeder]
- execute the [./bin/policy_seeder]
- execute the [./bin/jwt]
- execute the [./bin/jwt -env=.env.testing]
- make test
- go run cmd/app/*
- curl http://127.0.0.1:8080/api/ping
The folder structure follows the project-layout.
The code in the internal folder that is designed for project, so you can change it by yourself.
The pkg folder inside the internal folder is that it is reused package only for THIS project.
The pkg folder outside the internal folder is the reused package. In the future, I plan to make it to standalone package.
The permission management use the casbin. Please read document to understand.
Use air to run development server. You can follow .air.toml.example to set air configuration, or customize your configuration file.
The makefile contains build command, test command and database migration command ...etc.
- gin
- go-playground-validator
- go-playground-form
- go-playground-mold
- jwt-go
- gorm
- goose
- go-redis
- zap
- lumberjack
- godotenv
- viper
- pkg/errors
- casbin
- mapstructure
- structs
- argon2
- rate-limit
- testify
- swag
go-backend-framework
├── LICENSE
├── Makefile
├── README.md
├── bin
├── cmd
│ ├── app
│ │ └── main.go
│ ├── kit
│ │ ├── database_seeder
│ │ │ └── database_seeder.go
│ │ ├── http_route
│ │ │ └── http_route.go
│ │ ├── jwt
│ │ │ └── jwt.go
│ │ └── policy_seeder
│ │ └── policy_seeder.go
│ └── template
│ └── template.go
├── config.production.yml
├── config.testing.yml
├── config.yml
├── deployment
│ └── docker
│ └── Dockerfile
├── docs
│ ├── docs.go
│ ├── swagger.json
│ └── swagger.yaml
├── gbf-installer.sh
├── go.mod
├── go.sum
├── internal
│ ├── http
│ │ ├── controller
│ │ │ ├── admin
│ │ │ │ ├── admin_create_grouping_policy.go
│ │ │ │ ├── admin_create_grouping_policy_test.go
│ │ │ │ ├── admin_create_policy.go
│ │ │ │ ├── admin_create_policy_test.go
│ │ │ │ ├── admin_delete_grouping_policy.go
│ │ │ │ ├── admin_delete_grouping_policy_test.go
│ │ │ │ ├── admin_delete_policy.go
│ │ │ │ ├── admin_delete_policy_subject.go
│ │ │ │ ├── admin_delete_policy_subject_test.go
│ │ │ │ ├── admin_delete_policy_test.go
│ │ │ │ ├── admin_get_grouping_policy.go
│ │ │ │ ├── admin_get_grouping_policy_test.go
│ │ │ │ ├── admin_get_policy_subject.go
│ │ │ │ ├── admin_get_policy_subject_test.go
│ │ │ │ ├── admin_reload_policy.go
│ │ │ │ ├── admin_reload_policy_test.go
│ │ │ │ ├── admin_search_policy_subject.go
│ │ │ │ └── admin_search_policy_subject_test.go
│ │ │ └── user
│ │ │ ├── user_login.go
│ │ │ ├── user_login_test.go
│ │ │ ├── user_me.go
│ │ │ ├── user_me_test.go
│ │ │ ├── user_register.go
│ │ │ ├── user_register_test.go
│ │ │ ├── user_update.go
│ │ │ ├── user_update_password.go
│ │ │ ├── user_update_password_test.go
│ │ │ └── user_update_test.go
│ │ ├── middleware
│ │ │ ├── access_log_middleware.go
│ │ │ ├── authentication_middleware.go
│ │ │ ├── authorization_middleware.go
│ │ │ ├── global_middleware.go
│ │ │ ├── rate_limit_middleware.go
│ │ │ ├── recover_middleware.go
│ │ │ └── verify_csrf_token_middleware.go
│ │ ├── response
│ │ │ ├── error_message.go
│ │ │ ├── error_message_test.go
│ │ │ ├── error_response.go
│ │ │ └── response.go
│ │ ├── route
│ │ │ ├── admin
│ │ │ │ └── api_route.go
│ │ │ ├── api_route.go
│ │ │ ├── swagger_route.go
│ │ │ └── user
│ │ │ └── api_route.go
│ │ └── server.go
│ ├── migration
│ │ ├── 20230818113729_create_users_table.sql
│ │ ├── seeder
│ │ │ ├── seeder.go
│ │ │ └── user_seeder.go
│ │ └── test
│ │ └── 20230818113729_create_users_table.sql
│ ├── pkg
│ │ └── user
│ │ ├── model
│ │ │ └── user.go
│ │ └── user.go
│ ├── registrar
│ │ ├── authentication_registrar.go
│ │ ├── casbin_registrar.go
│ │ ├── database_registrar.go
│ │ ├── logger_registrar.go
│ │ ├── mapstructure_decoder_registrar.go
│ │ ├── redis_registrar.go
│ │ ├── register_executor.go
│ │ ├── registrar_test.go
│ │ └── simple_register_executor.go
│ ├── scheduler
│ │ ├── job
│ │ │ └── example_job.go
│ │ └── scheduler.go
│ └── test
│ ├── admin.go
│ ├── http.go
│ ├── migration.go
│ ├── test.go
│ └── user.go
└── storage
└── log
├── access.log
└── app.log
Introduction that it will introduce the IMPORTANT folders and packages.
The app folder includes core code in the application. You can add the custom folder in the app folder.
-
app
- Define the lifecycle for your app.
- The lifecycle has three stage that are starting, started and terminated.
- You can use callback function at any stage.
-
booter
- The booter package define how to boot the your app.
- Booter has config registry and service registry to store the config and instance of the struct by singleton pattern.
- To store config and instance. You can follow the internal/registrar package. It has the example to show how to do it.
The internal folder only use for this project. It always design for business logic.
Design for reused business logic.
It contains database migration that make from the goose.
The makefile integrates the migration commands. You can use it to add new migration and run any migration command.
It contains database migrations for testing. The testing migration use sqlite in memory database to testing.
It contains database seeders.
It contains all http relation functions.
It use internal/pkg, third party package and so on to construct the http endpoint.
It contains middlewares for http request and response.
It defines response format for the http response.
It defines http routes.
It has testing initializer and useful testing function that customizes for the go backend framework.
If you use the code base of the go backend framework, I suggest you to use testify to initialize your test case before you run the test case.
All testing data are stored in the sqlite, so you have install sqlite and write testing migration to test. If you don't want to use sqlite, you have to change the config.testing.yml.
Please see the testing example in the internal/http/controller!
It has all command from the project.
It is the main command in this project. If you execute it, the http server will be started.
It has the useful commands to help you develop the app.
For example, create jwt, database seeder executer, http route list and predefined permissions.
It is the command 6841 template. If you want to use config registry and provider registry, you can use this template.
It use for static file. Currently, it only has app log and access log.
It contains binary file from the cmd folder.
The docs folder is generated by swag. It is swagger api document.