Coder Social home page Coder Social logo

orderserve-go's Introduction

ginger

Directory structure for sample golang project development.

There are several ways to use it.

Run debug mode directly

$ vi app.debug.json
$ go run main.go bindata.go    # To avoid syntaxx error only. (bindata.go only used in release mode)

Deploy release mode directly

# 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/

Deploy & Run release with docker locally

$ vi setting/app.release.json
$ dkc -f docker-compose-from-src.yml up -d --build --force-recreate

Deploy in CI/CD way (Github Actions)

# 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

Preset features

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

Development workflow

main.go ->
route/api.go ->
	app/http/xx.go
	app/request/xxxParams.go
	app/repository/xxxRepo.go <- app/model/xxx.go
				  <- config/database.go

Pkg

golang-migrate

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

uuid

https://github.com/google/uuid

https://godoc.org/github.com/google/uuid

gorm

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

https://gorm.io/zh_CN/docs/index.html#%E5%AE%89%E8%A3%85

alipay

https://github.com/smartwalle/alipay

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.