Skip to content

Enterprise-grade Go web backend scaffolding based on cobra, viper, pflag, zap, gorm, gin.

License

Notifications You must be signed in to change notification settings

windvalley/gobackend

Repository files navigation

GoBackend

Language Github Workflow Status Quality Gate Status Lines of Code Bugs License
Page Views Traffic Clones Total Traffic Clones Uniques

Enterprise-grade Go web backend scaffolding based on cobra, viper, pflag, zap, gorm, gin.

Features

  • Project directories layout follows golang-standards/project-layout

  • The configuration items in the configuration file are unified with the command line parameters, and the command line parameters take precedence(Realized by cobra, viper and pflag).

  • Powerful logger built with zap and lumberjack, supports color, function caller, hooks, multi-outputs, rotation, etc.

  • Integrated many useful middlewares, which can be flexibly configured in the configuration file.

  • One server process can enable both http and https services at the same time.

  • Server graceful shutdown.

  • Custom your own environment variable to specify run environments(dev/test/prod).

  • Supports operation logging and exposes related restful apis.

  • Auto generate error code documentation file and necessary error code source files.

  • Supports application process lock.

  • Supports cloud native deployment.

  • Use Makefile to manage the project efficiently and conveniently.

  • Testable and maintainable codes.

Quik Start

$ git clone --depth 1 https://github.com/windvalley/gobackend.git

$ cd gobackend

Edit configs/dev.gobackend-apiserver.yaml:

# MySQL
mysql:
  # Default: 127.0.0.1:3306
  host: 127.0.0.1:3306
  # Default: ""
  username: "root"
  # Default: ""
  password: "123456"
  # Default: ""
  database: "gobackend"

Create database:

$ mysql -h 127.0.0.1 -P 3306 -uroot -p'123456' -e "create database gobackend;"

Run in development environment:

$ make run.dev

run_dev

Makefile

$ make

Usage: make [TARGETS] [OPTIONS]

Targets:

   all               Make gen, lint, cover, build
   run.dev           Run in development mode.
   run.test          Run in test mode.
   build             Compile packages and dependencies to generate binary file for current platform.
   build.multiarch   Build for multiple platforms. See option PLATFORMS.
   image             Build docker images for host arch.
   push              Build docker images for host arch and push images to registry.
   lint              Check syntax and style of Go source code.
   test              Run unit test.
   cover             Run unit test and get test coverage.
   gen               Generate necessary source code files and doc files.
   clean             Remove all files that are created by building.
   help              Show this help.

Options:

   BINS        The binaries to build. Default is all commands in cmd/.
               This option is available for: make build/build.multiarch
               Example: make build BINS="apiserver otherbinary"
   IMAGES      Docker images to build. Default is all commands in cmd/.
               This option is available when using: make image/image.multiarch.
               Example: make image.multiarch IMAGES="apiserver otherbinary"
   PLATFORMS   The multiple platforms to build.
               Default is 'darwin_amd64 darwin_arm64 linux_amd64 linux_arm64 windows_amd64'.
               This option is available when using: make build.multiarch.
               Example: make build.multiarch PLATFORMS="linux_amd64"

License

This project is under the MIT License. See the LICENSE file for the full license text.

About

Enterprise-grade Go web backend scaffolding based on cobra, viper, pflag, zap, gorm, gin.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages