ginmiddleware

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Constants

View Source
const (
	RequestLogChar  string = "RequestLog"
	ResponseLogChar string = "ResponseLog"
	TimeStamp       string = "TimeStamp"
	Method          string = "Method"
	Host            string = "Host"
	Uri             string = "Uri"
	ReqHeader       string = "ReqHeader"
	ReqBody         string = "ReqBody"
	RespHeader      string = "RespHeader"
	RespBody        string = "RespBody"
	StatusCode      string = "StatusCode"
	Latency         string = "Latency"
)
View Source
const (
	ContextKey = "contextMetaKey"
)
View Source
const (
	DebugStack string = "DebugStack"
)

Variables

View Source
var (
	JWTHeaderAuthToken   = HeaderAuthToken{Key: "Authorization", ValueHeader: "bearer"}
	BasicHeaderAuthToken = HeaderAuthToken{Key: "Authorization", ValueHeader: "basic"}
	JWTQueryAuthToken    = QueryAuthToken{Key: "access_token"}
)
View Source
var AuthPayload string = "auth-payload"
View Source
var (
	ErrorHeaderAuthFormat = errors.New("error header auth format")
)
View Source
var HeaderXRequestID string = "X-Request-ID"

Functions

func AddRequestID

func AddRequestID() gin.HandlerFunc

func CtxLogger

func CtxLogger(ctx context.Context) *zerolog.Logger

CtxLogger put the ContextMetaData of incoming context into log

func InjectContextRequestHeader

func InjectContextRequestHeader(ctx context.Context, req *http.Request)

func NewContextWithMeta

func NewContextWithMeta(ctx context.Context) context.Context

NewContextWithMeta new a context with incoming context metadata when we want to run a go routine in background, we should use this function and also can get those metadata from output context

func Recovery

func Recovery(writer io.Writer) gin.HandlerFunc

func WithMoreContextMeta

func WithMoreContextMeta(ctx context.Context, data ...ContextMetaData) context.Context

WithMoreContextMeta add extra ContextMetaData to incoming context

Types

type AuthMiddleware

type AuthMiddleware struct {
	GetToken      IgetAuthToken
	Authenticator IAuthenticator
}

func (*AuthMiddleware) GetAuthPayload

func (auth *AuthMiddleware) GetAuthPayload(c *gin.Context) (interface{}, bool)

func (*AuthMiddleware) ValidateAuth

func (auth *AuthMiddleware) ValidateAuth() gin.HandlerFunc

type ContextMetaData

type ContextMetaData struct {
	Key   string
	Value string
}

func GetContextMetaData

func GetContextMetaData(ctx context.Context) []ContextMetaData

GetContextMetaData get GetContextMetaData slice from incoming context

type ContextMetaKey

type ContextMetaKey string

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (*Error) Error

func (e *Error) Error() string

type HeaderAuthToken

type HeaderAuthToken struct {
	Key         string
	ValueHeader string
}

func (*HeaderAuthToken) GetAuthToken

func (h *HeaderAuthToken) GetAuthToken(r *http.Request) (string, error)

type IAuthenticator

type IAuthenticator interface {
	Authenticate(token string) (interface{}, *Error)
}

type IgetAuthToken

type IgetAuthToken interface {
	GetAuthToken(*http.Request) (string, error)
}

type JWTAuthenticator

type JWTAuthenticator struct {
	Audience        string
	Issuer          string
	GetPublicSecret func(*jwt.Token) (interface{}, error)
}

func (*JWTAuthenticator) Authenticate

func (a *JWTAuthenticator) Authenticate(token string) (interface{}, *Error)

type PathSettings

type PathSettings struct {
	Path          string
	DisableLogs   bool
	DisableBodies bool
}

type QueryAuthToken

type QueryAuthToken struct {
	Key string
}

func (*QueryAuthToken) GetAuthToken

func (q *QueryAuthToken) GetAuthToken(r *http.Request) (string, error)

type RequestLog

type RequestLog struct {
	Output       io.Writer
	Settings     []PathSettings
	MaskedFields []string
	TimeFormat   string
}

func (*RequestLog) AddRequestLog

func (l *RequestLog) AddRequestLog() gin.HandlerFunc

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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