Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atopx/goapi
gin api template
https://github.com/atopx/goapi
gin gorm rest-api swagger template zap
Last synced: 3 days ago
JSON representation
gin api template
- Host: GitHub
- URL: https://github.com/atopx/goapi
- Owner: atopx
- License: mit
- Created: 2024-05-23T08:07:24.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-12-24T08:44:57.000Z (8 days ago)
- Last Synced: 2024-12-24T09:34:29.580Z (8 days ago)
- Topics: gin, gorm, rest-api, swagger, template, zap
- Language: Go
- Homepage:
- Size: 32.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:```bash
git clone https://github.com/atopx/goapi.git
```2. Init your app
```bash
cd goapi
./control init $NEW_NAME # example: ./control init newapp
```3. Change the configuration file:
```bash
cp conf/config.example.yaml conf/config.yaml
```4. Run the application:
```bash
go mod tidy
go run main.go
```5. Control script
```bash
./control { init $NEW_NAME | build | docker | docs | clean }
```## Codes Layout
```bash
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
```