gin

package module
v1.3.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 20 Imported by: 0

README

gin

gin logger extension

快速使用

日志扩展使用

import (
	"errors"
	"net/http"

	"github.com/gin-gonic/gin"
	ginEx "github.com/illidaris/gin"
	"github.com/illidaris/logger"
)

func main() {
    // init log core
    logger.OnlyConsole()
    // init gin
    router := gin.New()
    router.Use(ginEx.LoggerHandler())
    router.Use(ginEx.RecoverHandler())
    router.GET("/test", func(c *gin.Context) {
    c.String(http.StatusOK, "success")
    })
    router.GET("/error", func(c *gin.Context) {
    panic(errors.New("this is an error"))
    })
    ginEx.GracefulRun(context.Background(),router,":8080",time.Second*5)
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseGracefulRunWithAop added in v1.3.6

func BaseGracefulRunWithAop(ctx context.Context, srv *http.Server, addr string, timeout time.Duration, before func(port int), after func())

func CORSMiddleware added in v1.3.5

func CORSMiddleware() gin.HandlerFunc

CORSMiddleware 防跨域

func GracefulRun

func GracefulRun(ctx context.Context, e http.Handler, addr string, timeout time.Duration)

func GracefulRunWithAop added in v1.2.0

func GracefulRunWithAop(ctx context.Context, e http.Handler, addr string, timeout time.Duration, before func(port int), after func())

func LoggerHandler

func LoggerHandler() gin.HandlerFunc

LoggerHandler record log

Example
router.Use(LoggerHandler())
Output:

func ParamMiddleware added in v1.3.5

func ParamMiddleware(opts ...ParamMiddlewareOption) gin.HandlerFunc

ParamMiddleware 出参入参记录中间件

func RecoverHandler

func RecoverHandler() gin.HandlerFunc

RecoverHandler recover from panic

Example
router.Use(RecoverHandler())
Output:

func WithTrace

func WithTrace(c *gin.Context, birth time.Time) *gin.Context

WithTrace add trace log context

Types

type HTTPMetaData

type HTTPMetaData core.MetaData
const (
	HTTPStatusCode  HTTPMetaData = "statusCode"
	HTTPContentType HTTPMetaData = "contentType"
	HTTPMethod      HTTPMetaData = "httpMethod"
	HTTPPath        HTTPMetaData = "httpPath"
	HTTPQuery       HTTPMetaData = "httpQuery"
	HTTPClientIP    HTTPMetaData = "httpClientIp"
	HTTPUserAgent   HTTPMetaData = "httpUserAgent"
)

type ParamMiddlewareOption added in v1.3.5

type ParamMiddlewareOption func(opt *paramMiddlewareOptions)

func WithRequestContentLengthMax added in v1.3.5

func WithRequestContentLengthMax(max uint64) ParamMiddlewareOption

func WithResponseContentLengthMax added in v1.3.5

func WithResponseContentLengthMax(max uint64) ParamMiddlewareOption

Directories

Path Synopsis
_example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL