GithubHelp home page GithubHelp logo

lovecrossyou / go-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pinkhello/go-starter

0.0 1.0 0.0 105 KB

Go 服务框架脚手架. 整合 echo、swag、viper、nsq、logrus、fx、xorm、cobra 等第三方库

License: Apache License 2.0

Go 97.19% Dockerfile 2.81%

go-starter's Introduction

go-starter

Demo: 房产CRM

thirdparty

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

  1. docker network:go_starter_network
    > docker network create go_starter_network
  2. mysql & nsq
    # MYSQL start
    > cd deploy/mysql
    > docker-compose up -d
    # NSQ start
    > cd deploy/nsq
    > docker-compose up -d
  3. be server
    # go-starter start
    > cd deploy
    > docker-compose up -d
  4. 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,
        )
    }

go-starter's People

Contributors

netwalker2000 avatar pinkhello avatar

Watchers

 avatar

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.