Documentation
¶
Index ¶
- Constants
- Variables
- func AddRequestID() gin.HandlerFunc
- func CtxLogger(ctx context.Context) *zerolog.Logger
- func InjectContextRequestHeader(ctx context.Context, req *http.Request)
- func NewContextWithMeta(ctx context.Context) context.Context
- func Recovery(writer io.Writer) gin.HandlerFunc
- func WithMoreContextMeta(ctx context.Context, data ...ContextMetaData) context.Context
- type AuthMiddleware
- type ContextMetaData
- type ContextMetaKey
- type Error
- type HeaderAuthToken
- type IAuthenticator
- type IgetAuthToken
- type JWTAuthenticator
- type PathSettings
- type QueryAuthToken
- type RequestLog
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 NewContextWithMeta ¶
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 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 ¶
func GetContextMetaData ¶
func GetContextMetaData(ctx context.Context) []ContextMetaData
GetContextMetaData get GetContextMetaData slice from incoming context
type ContextMetaKey ¶
type ContextMetaKey string
type HeaderAuthToken ¶
func (*HeaderAuthToken) GetAuthToken ¶
func (h *HeaderAuthToken) GetAuthToken(r *http.Request) (string, error)
type IAuthenticator ¶
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 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
Source Files
¶
Click to show internal directories.
Click to hide internal directories.