Skip to content

atopx/goapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goapi

go1.22+

This is a template for creating a REST API using Golang, Gin, Gorm, Zap, and Swagger.

Features

  • Support databases: MySQL, PostgreSQL, and SQLite databases
  • Support docker
  • Performance optimization
  • Redoc and openapi documentation
  • Full chain trace of logs (use uber-zap)
  • Lightweight and fast
  • Licensed under the MIT License

Installation

  1. Clone the repository:
git clone https://github.com/atopx/goapi.git
  1. Init your app
cd goapi
./control init $NEW_NAME # example: ./control init newapp
  1. Change the configuration file:
cp conf/config.example.yaml conf/config.yaml
  1. Run the application:
go mod tidy
go run main.go
  1. Control script
./control { init $NEW_NAME | build | docker | docs | clean }

Codes Layout

goapi
├── common # common package
│   ├── handle # global handlers
│   │   └── db.go
│   ├── logger # global logger
│   │   ├── gorm.go
│   │   └── logger.go
│   ├── middleware # router middleware
│   │   ├── context.go
│   │   └── recover.go
│   ├── system # api response
│   │   ├── consts.go
│   │   └── response.go
│   └── utils # frequently used functions
│       ├── sql.go
│       └── trace.go
├── conf # configuration file
│   ├── config.example.yaml
│   ├── config.go
│   └── config.yaml
├── docs # redoc and openapi documentation
├── internal # internal logic
│   ├── api # define api
│   │   ├── server.go
│   │   └── user.go
│   ├── biz # business logic
│   │   └── user
│   │       └── list
│   │           ├── action.go
│   │           └── schema.go
│   ├── control # api controller interface
│   │   └── control.go
│   ├── model # db model
│   │   └── user.go
│   ├── server # api server
│   │   ├── router.go
│   │   └── server.go
│   └── worker # async workers
│       ├── health
│       │   └── task.go
│       └── worker.go
├── pkg # third-party packages
│   ├── db.go
│   └── redis.go
└── tests # tests
    └── config_test.go