Giter VIP home page Giter VIP logo

go-web-skeleton's Introduction

Go Web Skeleton

A complete Golang web application skeleton.

中文说明

Contains:

  • Can be used for API interface applications, CLI command line applications, WEB applications
  • Log library logrus configuration used
  • swagger API documentation configuration generation
  • Multi-language support, view rendering, request data validation
  • Configure read management, load according to environment, multi-file support
  • Contains redis, mysql, mongo for initialization and simple use
  • Use go mod to install the management dependencies

Project Structure

Github 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.
...

Used Packages

Auxiliary Library

  • swagger document generation:
    • go-swagger The documentation is complex but more powerful
    • swaggo/swag Documents and usage are relatively simple, only generating documents is enough
  • Test the auxiliary library for quick assertion stretchr/testify
  • Debugging tool: davecgh/go-spew Deep printing golang variable data

Additional components

  • swagger UI: swagger document rendering
  • Dockerfile: docker image build script for production environment, based on alpine, build a project image with an estimated size of around 30 M
  • makefile: Some quick-on make commands have been built to help quickly generate documentation and build images.

Start

  • First, clone the skeleton repository to your local directory
  • Rename the go-web-skeleton directory to your project name.
  • Go to the project and replace github.com/inhere/go-web-skeleton with your project name (for go file)
  • Search again and replace all go-web-skeleton with your project name (mainly Dockerfile, makefile)
  • Run go mod tidy to install dependent libraries
  • Run the project: go run main.go

Swagger Docs Generation

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"`
}	

Help

  • Run the test
Go test
// output coverage
Go test -cover
  • Formatting project
gofmt -s -l ./
go fmt ./...
  • Run GoLint check

Note: You need to install GoLint first.

golint ./...

Refer

License

MIT

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.