Directory structure for sample golang project development.
There are several ways to use it.
$ vi app.debug.json
$ go run main.go bindata.go # To avoid syntaxx error only. (bindata.go only used in release mode)
# Update setting
$ cp app.mode.json.example app.release.json
$ vi app.release.json
# Build & distribute
$ go-bindata -o bindata.go setting/ # generate bindata.go that is load for release mode which will never be changed
$ export GIN_MODE=release
$ "go build && ./ginger" OR "go run main.go bindata.go"
# Optional
$ scp ginger [email protected]:/dist/
$ vi setting/app.release.json
$ dkc -f docker-compose-from-src.yml up -d --build --force-recreate
# Update and push to release/prod branch trigger actions
$ vi .github/workflows/go.yml
# On remote server
$ cd gingerApi/dist
$ dkc -f docker-compose-from-dist.yml up -d --build --force-recreate
Support global CORS middleware.
Support global Request Rate limit middleware.
Support config set by Viper in config/
Support load setting/ value into build binary by Working with bindata.go
Support production ready Docker environment out of box.
Support migration in migrate.go
main.go ->
route/api.go ->
app/http/xx.go
app/request/xxxParams.go
app/repository/xxxRepo.go <- app/model/xxx.go
<- config/database.go
CLI install: https://github.com/golang-migrate/migrate/tree/master/cmd/migrate
MySQL driver: https://github.com/golang-migrate/migrate/tree/master/database/mysql
CLI example
$ migrate create -ext sql -dir db/migrations -seq create_orders_table
$ migrate -path db/migrations -database "mysql://root:123456@(127.0.0.1:33056)/testdb?multiStatements=true" up
$ migrate -path db/migrations -database "mysql://root:123456@(127.0.0.1:33056)/testdb?multiStatements=true" version
$ migrate -path db/migrations -database "mysql://root:123456@(127.0.0.1:33056)/testdb?multiStatements=true" force <2>
$ migrate -path db/migrations -database "mysql://root:123456@(127.0.0.1:33056)/testdb?multiStatements=true" down
https://github.com/google/uuid
https://godoc.org/github.com/google/uuid
Official example:
$ go get -u gorm.io/gorm
$ go get -u gorm.io/driver/mysql
$ go get -u gorm.io/driver/sqlite
https://gorm.io/zh_CN/docs/models.html
https://gorm.io/zh_CN/docs/connecting_to_the_database.html