go-gin-web

module
v0.0.0-...-d4f785a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2025 License: MIT

README

English | 简体中文

Project Overview

go-gin-web is an engineering practice project built from scratch using Go, based on the Gin framework. It aims to provide a cleanly layered, maintainable, scalable, and developer-friendly backend service structure.


Features

  • Clear Project Structure: Inspired by project-layout, follows layered architecture principles, organized for team collaboration and long-term maintenance.
  • Common Component Integration: Includes built-in examples for MySQL, Redis, and Elasticsearch.
  • Full Link Logging: Provides a custom logging package glog based on zap, supporting full trace ID propagation across MySQL, Redis, ES, and HTTP calls.
  • Code Generation Tool: Comes with a command-line tool gocli that can generate standardized code (including model, dao, object, dto, code, service, controller, router layers) based on config.
  • Swagger API Documentation: Automatically generate interactive API docs using swaggo for easier frontend-backend collaboration and testing.
  • Docker Support: Includes a basic Dockerfile for containerized deployment.
  • Makefile Toolchain: Provides a rich set of make commands to simplify code build, run, generation, Swagger docs, and Docker deployment.
  • Growing Golib Library: Common utility components are abstracted and reusable via the golib package.

Project Structure

Follows project-layout. Current structure:

.
├── apps
│   ├── demoapp
│   │   ├── cmd
│   │   ├── client
│   │   │   └── httpbingo
│   │   ├── config
│   │   ├── dao
│   │   │   └── daouser
│   │   ├── docs
│   │   ├── internal
│   │   │   ├── controller
│   │   │   │   ├── ctrexample
│   │   │   │   └── ctruser
│   │   │   ├── dto
│   │   │   │   ├── dtoexample
│   │   │   │   └── dtouser
│   │   │   └── service
│   │   │       ├── svcexample
│   │   │       └── svcuser
│   │   ├── middleware
│   │   ├── model
│   │   ├── object
│   │   │   ├── objcommon
│   │   │   └── objuser
│   │   ├── router
│   │   └── scripts
│   └── newapp
├── log
├── output
│   └── build
├── pkg
│   ├── code
│   ├── storages
│   ├── testutil
│   └── utils
└── scripts
    └── sql

Core Features

Code Generation

Install the CLI tool:

go install github.com/morehao/gocli@latest

Ensure a code_gen.yaml config file exists under the application directory, e.g., go-gin-web/apps/demoapp/config/code_gen.yaml.

Run code generation commands:

# Generate full module based on table
make codegen MODE=module APP=demoapp

# Generate only model code
make codegen MODE=model APP=demoapp

# Generate API endpoint code
make codegen MODE=api APP=demoapp

See generate for full documentation.


API Documentation

Install Swagger tool:

go install github.com/swaggo/swag/cmd/swag@latest

Generate Swagger docs:

make swag APP=demoapp

Access docs at:

http://localhost:8099/demoapp/swagger/index.html

Project Deployment

Build Docker image:

make docker-build APP=demoapp

Run container:

make docker-run APP=demoapp

Quickly Scaffold a New Project

Install the cutter tool:

go install github.com/morehao/gocli@latest

Run under the root of the template project (e.g., ./):

gocli cutter -d /goProject/yourAppName

This will scaffold a new project named yourAppName under /goProject based on the current template.

See cutter for more usage details.


All related components are implemented in the golib package.

Directories

Path Synopsis
apps
demoapp/client/httpbingo
* @Author: morehao morehao@qq.com * @Date: 2025-11-08 17:44:59 * @LastEditors: morehao morehao@qq.com * @LastEditTime: 2025-11-08 17:46:54 * @FilePath: /golib/Users/morehao/Documents/practice/go/go-gin-web/apps/demoapp/client/httpbingo/httpbingo.go * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @Author: morehao morehao@qq.com * @Date: 2025-11-08 17:44:59 * @LastEditors: morehao morehao@qq.com * @LastEditTime: 2025-11-08 17:46:54 * @FilePath: /golib/Users/morehao/Documents/practice/go/go-gin-web/apps/demoapp/client/httpbingo/httpbingo.go * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
demoapp/cmd command
demoapp/docs
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL