ginx

package
v0.0.0-...-c844e6a Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GinContextContext = "context" // GinContextContext 存在 gin context 中的标准库 context 实例的 key
	HTTPTraceIDHeader = "x-trace-id"
	ContextTraceID    = contextKey(HTTPTraceIDHeader)
)

Variables

This section is empty.

Functions

func BindJSON

func BindJSON(c *gin.Context, param interface{})

func BindQuery

func BindQuery(c *gin.Context, param interface{})

func BindXML

func BindXML(c *gin.Context, param interface{})

func BombErr

func BombErr(code int, format string, p ...interface{})

func CustomErr

func CustomErr(v interface{}, code ...int)

func DefaultTodoContext

func DefaultTodoContext(ctx *gin.Context) context.Context

func DisableConsoleColor

func DisableConsoleColor()

DisableConsoleColor disables color output in the console.

func ErrorLogger

func ErrorLogger() gin.HandlerFunc

ErrorLogger returns a handlerfunc for any error type.

func ErrorLoggerT

func ErrorLoggerT(typ gin.ErrorType) gin.HandlerFunc

ErrorLoggerT returns a handlerfunc for a given error type.

func ForceConsoleColor

func ForceConsoleColor()

ForceConsoleColor force color output in the console.

func Logger

func Logger() gin.HandlerFunc

Logger instances a Logger middleware that will write the logs to gin.DefaultWriter. By default gin.DefaultWriter = os.Stdout.

func LoggerWithConfig

func LoggerWithConfig(conf LoggerConfig) gin.HandlerFunc

LoggerWithConfig instance a Logger middleware with config.

func LoggerWithFormatter

func LoggerWithFormatter(f LogFormatter) gin.HandlerFunc

LoggerWithFormatter instance a Logger middleware with the specified log format function.

func LoggerWithWriter

func LoggerWithWriter(out io.Writer, notlogged ...string) gin.HandlerFunc

LoggerWithWriter instance a Logger middleware with the specified writer buffer. Example: os.Stdout, a file opened in write mode, a socket...

func QueryBool

func QueryBool(c *gin.Context, key string, defaultVal ...bool) bool

func QueryInt

func QueryInt(c *gin.Context, key string, defaultVal ...int) int

func QueryInt64

func QueryInt64(c *gin.Context, key string, defaultVal ...int64) int64

func QueryStr

func QueryStr(c *gin.Context, key string, defaultVal ...string) string

func Recovery

func Recovery() gin.HandlerFunc

Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.

func RecoveryWithWriter

func RecoveryWithWriter(out io.Writer) gin.HandlerFunc

RecoveryWithWriter returns a middleware for a given writer that recovers from any panics and writes a 500 if there was one.

func ShouldGetTraceID

func ShouldGetTraceID(c context.Context) (traceID string)

func URLParamInt

func URLParamInt(c *gin.Context, field string) int

func URLParamInt64

func URLParamInt64(c *gin.Context, field string) int64

func URLParamStr

func URLParamStr(c *gin.Context, field string) string

Types

type LogFormatter

type LogFormatter func(params LogFormatterParams) string

LogFormatter gives the signature of the formatter function passed to LoggerWithFormatter

type LogFormatterParams

type LogFormatterParams struct {
	Request *http.Request

	// TimeStamp shows the time after the server returns a response.
	TimeStamp time.Time
	// StatusCode is HTTP response code.
	StatusCode int
	// Latency is how much time the server cost to process a certain request.
	Latency time.Duration
	// ClientIP equals Context's ClientIP method.
	ClientIP string
	// Method is the HTTP method given to the request.
	Method string
	// Path is a path the client requests.
	Path string
	// ErrorMessage is set if error has occurred in processing the request.
	ErrorMessage string

	// BodySize is the size of the Response Body
	BodySize int
	// Keys are the keys set on the request's context.
	Keys map[string]interface{}
	// contains filtered or unexported fields
}

LogFormatterParams is the structure any formatter will be handed when time to log comes

func (*LogFormatterParams) IsOutputColor

func (p *LogFormatterParams) IsOutputColor() bool

IsOutputColor indicates whether can colors be outputted to the log.

func (*LogFormatterParams) MethodColor

func (p *LogFormatterParams) MethodColor() string

MethodColor is the ANSI color for appropriately logging http method to a terminal.

func (*LogFormatterParams) ResetColor

func (p *LogFormatterParams) ResetColor() string

ResetColor resets all escape attributes.

func (*LogFormatterParams) StatusCodeColor

func (p *LogFormatterParams) StatusCodeColor() string

StatusCodeColor is the ANSI color for appropriately logging http status code to a terminal.

type LoggerConfig

type LoggerConfig struct {
	// Optional. Default value is gin.defaultLogFormatter
	Formatter LogFormatter

	// Output is a writer where logs are written.
	// Optional. Default value is gin.DefaultWriter.
	Output io.Writer

	// SkipPaths is a url path array which logs are not written.
	// Optional.
	SkipPaths []string
}

LoggerConfig defines the config for Logger middleware.

type Render

type Render struct {
	// contains filtered or unexported fields
}

func NewRender

func NewRender(c *gin.Context, code ...int) Render

func (Render) Data

func (r Render) Data(data interface{}, err interface{}, a ...interface{})

func (Render) DataString

func (r Render) DataString(data string, err interface{}, a ...interface{})

func (Render) Message

func (r Render) Message(v interface{}, a ...interface{})

func (Render) RawString

func (r Render) RawString(data string)

Jump to

Keyboard shortcuts

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