Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mix-go/gin
Gin based Web library, extend Logrus support
https://github.com/mix-go/gin
gin logrus
Last synced: 3 months ago
JSON representation
Gin based Web library, extend Logrus support
- Host: GitHub
- URL: https://github.com/mix-go/gin
- Owner: mix-go
- License: apache-2.0
- Archived: true
- Created: 2020-08-28T08:57:47.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-25T07:06:25.000Z (about 4 years ago)
- Last Synced: 2023-07-28T12:57:49.879Z (over 1 year ago)
- Topics: gin, logrus
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
> OpenMix 出品:[https://openmix.org](https://openmix.org/mix-go)
## Mix Gin
基于 Gin 的 Web 库, 扩展 logrus 支持
Gin based Web library, extend Logrus support
## Overview
与原版 `Gin` 有哪些不同?
- 扩展了通过 `func(router *gin.Engine)` 闭包初始化路由的方式,方便路由定义规划。
- 扩展了路由日志对第三方 `logger` 的支持,包括:`logrus` 等。## Installation
- 安装
```
go get -u github.com/mix-go/gin
```## Usage
通过闭包创建路由
```go
routeDefinitionCallback := func(router *gin.Engine) {
router.GET("hello",
middleware.CorsMiddleware(),
func(ctx *gin.Context) {
hello := controllers.HelloController{}
hello.Index(ctx)
},
)router.POST("users/add",
middleware.CorsMiddleware(),
func(ctx *gin.Context) {
hello := controllers.AddUserController{}
hello.Index(ctx)
},
)router.POST("auth", func(ctx *gin.Context) {
auth := controllers.AuthController{}
auth.Index(ctx)
})
}
router := gin.New(routeDefinitionCallback)
```接入第三方 `logrus` 打印日志
```go
logger := logrus.NewLogger()
router.Use(gin.LoggerWithFormatter(logger, func(params gin.LogFormatterParams) string {
return fmt.Sprintf("%s|%s|%d|%s",
params.Method,
params.Path,
params.StatusCode,
params.ClientIP,
)
}))
```可以接入实现以下接口的所有第三方日志组件
```go
type Logger interface {
Info(args ...interface{})
}
```## License
Apache License Version 2.0, http://www.apache.org/licenses/