The open source project is: Go-Gin-API, currently 800+ Star.

Go-gin-api is a modular API framework based on GIN. It encapsulates common functions and is easy to use. It is dedicated to fast business development.

Download and run directly

$git clone https://github.com/xinliangnote/go-gin-api $CD go - gin - API $go run. Main go - env fat / / - env fat is set to the test environmentCopy the code

First, go to the service initialization interface.

Then fill inMySQL,RedisAfter filling in the configuration information, click the initialization button.

As shown in the preceding figure, the service is successfully initialized. You need to restart the service. After the service is started, the login page is displayed.

Use the default user admin to log in. After a successful login, the dashboard is displayed.

What functions have been integrated?

The alarm is notified by email when Panic occurs

The email 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, the caller KEY, caller SECRET, caller interlocutor, remarks and other information can be set.

You can send the KEY and SECRET of the created caller to the caller, enable/disable/delete the caller, and authorize the accessible interface to the caller.

Interface authentication stores signature information based on the Authorization and authorization-date parameters in the HTTP Header. The code provides three encryption algorithms: Go, PHP, and JS.

Code generation tool

Gormgen, based on the data table generated three files, with the ADMIN table as the regular meeting to generate: gen_table.md table annotated MD document, gen_model.go table field structure, gen_admin.go table CURD operation code.

Significance: In the development of business requirements, after creating the data table, the code generation tool is executed, and the commonly used CURD operations are all generated, and only need to be used. The latter method is fine, which greatly improves business development efficiency.

Handlergen, based on the defined Handler file type interface{} interface method, generated file.

For example, the method defined is:

// @tags api. admin/ / @router/API /admin/ Login [post] Login() core.handlerFuncCopy the code

The generated method is as follows:

Type loginRequest struct {} type loginResponse struct {} // Login Administrator Login // @summary administrator Login // @description administrator Login // @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) { } }Copy the code

Significance: The person in charge of the research and development of this requirement defines the methods to be developed by defining type interface{}, and executes the code generation tool. The empty implementation of each method will be generated in a separate file, and the developers only need to implement their own methods to facilitate the division of labor and code management.

The interface log

The link ID can be used to string the request information, response information, information about invoking the third-party HTTP interface, information about invoking the third-party gRPC interface, debugging information, SQL information, and Redis information, and record the information in the log.

Click a row to view log details.

Interface documentation

The code generated by the handler comes with its own interface documentation.

The interface index

Projects collected Prometheus used in the index, the default open metrics records, can through http://127.0.0.1:9999/metrics can look at it.

GraphQL

The project uses GQLGen to implement the GraphQL query, which is different from the demo initialized by GQLGen Init because the code is already integrated into the GO-Gin-API, such as integrating links, logs, and so on in the project core package.

Only Demo is implemented so far, and Resolver uses simulated data, but reusable services are also implemented. The code is annotated, so you can explore further if you are interested.

Prometheus

To start the Prometheus configuration file, see:

  • ./deploy/prometheus/prometheus.yml

Similar effect:

Loki

Loki is a horizontally scalable, highly available, multi-tenant log aggregation system for those interested.

To enable Loki configuration files, see:

  • ./deploy/loki/loki.yaml
  • ./deploy/loki/promtail.yaml

Which components are in use?

  • Rate Interface traffic limiting
  • Supports email notification of panic exceptions
  • Cross-domain CORS interfaces are supported
  • Record Prometheus indicators
  • Supports Swagger interface document generation
  • Support GraphQL query language
  • Support trace project internal link tracing
  • Support for PPROF performance profiling
  • Supports JWT interface authentication
  • Support errNO to define error codes uniformly
  • Supports ZAP log collection
  • Supports viper configuration file parsing
  • Support for gorM database components
  • Support for go-Redis components
  • RESTful API return value specification is supported
  • Support gormGen, Handlergen code generation tools
  • Supports the Web interface and uses the Light Year Admin template

The project address

The source address

Github.com/xinliangnot…

Online documentation

www.yuque.com/xinliangnot…

If you have good ideas and suggestions, welcome to add friends to communicate.