interceptor

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UidHeader       = "X-Uid"
	DebugHeader     = "X-Debug"
	TokenHeader     = "X-Token"
	NonceHeader     = "X-Nonce"
	TimestampHeader = "X-Timestamp"
	SignHeader      = "X-Sign"
	LanguageHeader  = "X-Language"
	TokenPrefix     = "token#"
	UserPrefix      = "user#"
	CodeExpiryTime  = 15 * 60                 //15分钟
	TokenExpiryTime = 7 * 86400 * time.Second //7天
)

Variables

View Source
var (

	// ServerHandleCounter ...
	ServerHandleCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "",
			Name:      "http_server_handle_total",
		}, []string{"name", "method", "path", "host", "code"})

	// ServerHandleHistogram ...
	ServerHandleHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: "",
		Name:      "http_server_handle_seconds",
	}, []string{"name", "method", "path", "host"})
)

Functions

func Auth

func Auth(c *gin.Context)

Auth

func AuthJson

func AuthJson(c *gin.Context)

func Error

func Error(c *gin.Context, codeErr *code_err.CodeErr, err error)

func GetCurrentGoroutineStack

func GetCurrentGoroutineStack(err interface{}) []byte

GetCurrentGoroutineStack 获取当前Goroutine的调用栈,便于排查panic异常

func GetDuration

func GetDuration(ctx context.Context) time.Duration

func GetDurationMilliseconds

func GetDurationMilliseconds(ctx context.Context) float64

func GetStartTime

func GetStartTime(ctx context.Context) time.Time

func HeaderCarrierInterceptor

func HeaderCarrierInterceptor() gin.HandlerFunc

多个服务间透传参数

func HmacSHA256Sign

func HmacSHA256Sign(secret []byte, params []byte) (string, error)

sign

func Log

Log returns a middleware and handles the control to the centralized HTTPErrorHandler.

func LogJson

func LogJson(c *gin.Context, cfg *http_server_config.Config)

func Md5

func Md5(s string) string

func MetricInterceptor

func MetricInterceptor(cfg *http_server_config.Config) gin.HandlerFunc

func SetStartTimeInterceptor

func SetStartTimeInterceptor() gin.HandlerFunc

func Sha256

func Sha256(text []byte) []byte

func Sha256ToHex

func Sha256ToHex(text []byte) string

func Sign

func Sign(validateToken func(token string) (uid string, err error)) gin.HandlerFunc

Sign

func Timeout

func Timeout(timeout time.Duration) func(c *gin.Context)

timeout middleware wraps the request context with a timeout

func Token

func Token(c *gin.Context)

Token

func Trace

func Trace(ctx context.Context) gin.HandlerFunc

func ValidateSign

func ValidateSign(signParam string, appKey string, bodyParams []byte) (err error)

ValidateSign

Types

type BodyLogWriter

type BodyLogWriter struct {
	gin.ResponseWriter
	// contains filtered or unexported fields
}

func (BodyLogWriter) Write

func (w BodyLogWriter) Write(b []byte) (int, error)

func (BodyLogWriter) WriteString

func (w BodyLogWriter) WriteString(s string) (int, error)

type LogData

type LogData struct {
	RequestBody string `json:"request_body"`
}

Jump to

Keyboard shortcuts

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