go-starter
github activity
Demo
Demo: 房产CRM
- url: http://121.4.242.26 (test/123456)。
- BE go-starter
- FE ant-design-vue-pro
thirdparty
- Github Actions
- Custom Logger logrus
- CLI Command cobra
- Configuration viper
- Web echo
- DI/IOC fx
- ORM xorm
- Swagger generator swag echo-swagger
- Messaging NSQ
- golangci-lint golangci-lint
- Migrate migrate
- ......
code layer
- app # application main
- cmd
- ...
- config # config
- deploy # ci/cd
- mysql # mysql docker-compose
- nsq # nsq docker-compose
- ... # other
- docs # swag gen swagger2.0 doc
- internal # core
- controller # http handler(controller)
- http # http sever startup
- lib # lib
- models # models
- nsq # nsq producer & nsq consumer startup
- repository # repository
- service # service
- utils # util
- ...
- ...
Build & Publish & Deploy
swag tips
> swag init -g app/main.go
swagger url: http://{IP}:{PORT}/swagger/index.html
build
- local
> cd . > docker build . --file deploy/Dockerfile --tag {ImageTag}
- github action
> { secrets.ACCESS_USERNAME }: `your docker hub username`
be deploy
docker network
:go_starter_network
> docker network create go_starter_network
mysql
&nsq
# MYSQL start > cd deploy/mysql > docker-compose up -d # NSQ start > cd deploy/nsq > docker-compose up -d
be server
# go-starter start > cd deploy > docker-compose up -d
Health
http://{IP}:{PORT}/
Other
-
Dockerfile
# build go FROM golang:1.16.1-alpine3.13 as builder ...... RUN CGO_ENABLED=0 GOOS=linux go build -o go_starter app/main.go # package stage FROM alpine ...... # copy from builder COPY --from=builder /app/go_starter /app # ......
-
Uber IOC/DI: fx
//other code ...... var ( httpCmd = &cobra.Command{ Use: "http", Short: "Start Http REST API", Run: initHTTP, } ) func initHTTP(cmd *cobra.Command, args []string) { fx.New(inject()).Run() } func inject() fx.Option { return fx.Options( fx.Provide( config.NewConfig, utils.NewTimeoutContext, ), libs.XormModule, repository.Module, service.Module, controller.Module, nsq.ProducerModule, nsq.ConsumerModule, http.Module, ) }