gitmyhub

go-gin-api

Go ★ 6.0k updated 2y ago

基于 Gin 进行模块化设计的 API 框架,封装了常用功能,使用简单,致力于进行快速的业务研发。比如,支持 cors 跨域、jwt 签名验证、zap 日志收集、panic 异常捕获、trace 链路追踪、prometheus 监控指标、swagger 文档生成、viper 配置文件解析、gorm 数据库组件、gormgen 代码生成工具、graphql 查询语言、errno 统一定义错误码、gRPC 的使用、cron 定时任务 等等。

Go API starter framework built on Gin with rate limiting, auth tokens, structured logging, database code generation, Redis, Swagger docs, and an admin web panel pre-wired.

GoGingormRedisSwaggerGraphQLsetup: moderatecomplexity 3/5

go-gin-api is a starter framework for building web APIs in the Go programming language. It is built on top of Gin, a popular Go library for handling HTTP requests, and adds a collection of pre-integrated tools so developers can get a working API up and running without wiring everything together from scratch.

The framework comes with a range of built-in features. It handles rate limiting, which is the ability to cap how many requests a particular endpoint accepts over a given time. It supports cross-origin requests, which is what allows web browsers on one domain to call an API hosted on a different domain. Authentication tokens, request tracing for diagnosing slow calls, and structured logging are also included. Errors across the application use a consistent numbering scheme so that callers always receive predictable error responses.

For databases, the framework integrates with gorm, a popular Go library for working with relational databases, and includes a code generator that can produce standard database read, write, update, and delete operations for a given data table. Redis, a fast in-memory data store, is also connected. Scheduled tasks can be configured and viewed through a built-in web admin interface.

The framework can also generate API documentation automatically using Swagger, which produces an interactive page listing all available endpoints and their parameters. There is optional GraphQL support for APIs that prefer that query style over traditional REST, and a WebSocket integration for real-time communication between server and client.

The README is written in Chinese, though an English version is linked separately. The repository describes itself as a learning reference and cautions against using it in production without careful review. A lighter version with fewer integrations is also mentioned for developers who want a simpler starting point.

Where it fits