A skeleton for golang web application(with logger, redis, mysql, mongo, config, i18n, cli, validate and more)
MIT License
A complete Golang web application skeleton.
Contains:
logrus
configuration usedgo mod
to install the management dependenciesGithub Project https://github.com/inhere/go-web-skeleton
api/ API interface application handlers
|- controller/
|- middleware/
|_ routes.go
app/ Common directory (public methods, application initialization, public components, etc.)
cmd/ CLI command line application commands
|_ cliapp/ command line application entry file (main)
config/ Application configuration directory (basic configuration plus various environment configurations)
model/ Data and logic code directory
|- form/ Request form structure data definition, form validation configuration
|- logic/ Logic processing
|- mongo/ MongoDB data collection model definition
|- mysql/ MySQL data form model definition
|_ rds/ Redis data model definition
resource/ Non-code resources used by some projects (language files, view template files, etc.)
runtime/ Temporary file directory (file cache, log files, etc.)
static/ Static resource directory (js, css, etc.)
main.go Web application entry file
Dockerfile Dockerfile
Makefile Has written some common shortcut commands to help package, build docker, generate documentation, run tests, etc.
...
render by
tree -d 2 ./
use ✅ mark current used go package
Provide HTTP service and routing
Other:
Command line application
Configuration management
Mysql:
Mongodb:
Redis:
Request data validation
High-performance serialization library
JSON:
Config register center:
Dockerfile
: docker image build script for production environment, based on alpine, build a project image with an estimated size of around 30 Mmakefile
: Some quick-on make commands have been built to help quickly generate documentation and build images.go-web-skeleton
directory to your project name.github.com/inhere/go-web-skeleton
with your project name (for go file)go-web-skeleton
with your project name (mainly Dockerfile, makefile)go mod tidy
to install dependent librariesgo run main.go
go run ./cmd/appinit
installation:
go get -u github.com/swaggo/swag/cmd/swag
Please check the documentation and examples of
swaggo/swag
Generated to the specified directory:
swag init -o static
# This file will be generated at the same time. It can be deleted if it is not needed.
rm static/docs.go
Notice:
swaggo/swag
is the parsing field description information from the comment of the field
type SomeModel struct {
// the name description
Name string `json:"name" example:"tom"`
}
Go test
// output coverage
Go test -cover
gofmt -s -l ./
go fmt ./...
Note: You need to install
GoLint
first.
golint ./...
MIT