This open source project is: go-gin-api
, currently 800+ Star.
go-gin-api
is an API framework based on Gin's modular design. It encapsulates commonly used functions, is simple to use, and is committed to rapid business research and development. At the same time, it adds more restrictions, restricts project team development members, and avoids chaos, disorder and freedom. coding.
Can be run directly after downloading
$ git clone https://github.com/xinliangnote/go-gin-api
$ cd go-gin-api
$ go run main.go -env fat // -env fat 设置为测试环境
First enter the service initialization interface.
Next, fill in the MySQL
and Redis
configuration information. After filling in, click the Initialize button.
As shown in the figure above, it means that the service is initialized successfully and the service needs to be restarted. After the service is started, you will see the login interface.
Use the default user information: admin
, admin
log in. After logging in successfully, you will see the dashboard interface.
What functions have been integrated?
Email alert notification when panic
Mail sender information can be configured in the background, as shown in the figure below:
The email template is as follows:
Interface authentication
In the background, you can set the caller KEY, caller SECRET, caller docking person, remarks and other information.
Just send the created KEY and SECRET of the caller to the caller. You can enable/disable/delete the caller, and you can also authorize the accessible interface.
Interface authentication is based on the two parameters Authorization
and Authorization-Date
in the HTTP Header to store the signature information. The code provides encryption algorithms in 3 languages: Go
, PHP
, JS
.
Code generation tool
gormgen
, three files are generated based on the data table. Taking the admin
table as an example, it will generate: gen_table.md
table annotated MD document, gen_model.go
table field structure, gen_admin.go
table CURD operation code.
Significance: When developing business requirements, after creating the data table, execute the code generation tool. The commonly used CURD operations are all generated, and only the latter method is needed when using it, which greatly improves the efficiency of business development.
handlergen
, based on the interface method in type interface{}
Handler
file, to generate the file.
For example, the defined method is:
// Login 管理员登录
// @Tags API.admin
// @Router /api/admin/login [post]
Login() core.HandlerFunc
The generated method is:
type loginRequest struct {
}
type loginResponse struct {
}
// Login 管理员登录
// @Summary 管理员登录
// @Description 管理员登录
// @Tags API.admin
// @Accept multipart/form-data
// @Produce json
// @Success 200 {object} loginResponse
// @Failure 400 {object} code.Failure
// @Router /api/admin/login [post]
func (h *handler) Login() core.HandlerFunc {
return func(c core.Context) {
}
}
Significance: The person in charge of R&D for this requirement defines type interface{}
, and executes the code generation tool. The empty implementation of each method will be generated in a separate file, and the developer only needs to implement the respective method That is, it is convenient for division of labor and code management.
Interface log
The link ID can be used to
request information,
response information,
calling third-party HTTP interface information,
calling third-party gRPC interface information,
debugging information,
executing SQL information,
executing Redis information , Recorded in the log.
Click on a row to view the log details.
Interface documentation
The code generated by handlergen
comes with interface documentation.
Interface index
The project uses prometheus
to collect metrics. The metrics record is turned on by default in the project, which can be viewed through http://127.0.0.1 :9999/metrics.
GraphQL
The project uses gqlgen
implement GraphQL query. You will find that it is different from the demo initialized by gqlgen init because the code has been integrated into go-gin-api, such as integrating the links and logs in the core package of the project.
At present, only Demo is implemented. The resolver uses simulated data, but the use of reusable service has also been implemented. The code has been annotated, and those who are interested can study in depth.
Prometheus
Start the configuration file of Prometheus
- ./deploy/prometheus/prometheus.yml
Similar effects:
Loki
Loki
is a horizontally scalable, high-availability, multi-tenant log aggregation system. If you are interested, you can study it.
To enable Loki
, please refer to:
- ./deploy/loki/loki.yaml
- ./deploy/loki/promtail.yaml
What components have been used?
- Support rate interface current limit
- Support email notification when panic is abnormal
- Support cors interface cross-domain
- Support Prometheus indicator recording
- Support Swagger interface document generation
- Support GraphQL query language
- Support trace project internal link tracking
- Support pprof performance analysis
- Support jwt interface authentication
- Support errno to define error codes uniformly
- Support zap log collection
- Support viper configuration file analysis
- Support gorm database components
- Support go-redis components
- Support RESTful API return value specification
- Support gormgen, handlergen code generation tools
- Support web interface, use Light Year Admin template
project address
Source address
https://github.com/xinliangnote/go-gin-api
Online documentation
https://www.yuque.com/xinliangnote/go-gin-api/ngc3x5
If you have good ideas and suggestions, welcome to add friends to communicate.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。