Documentation
¶
Index ¶
- Constants
- Variables
- func AddRequestID() gin.HandlerFunc
- func CtxLogger(ctx context.Context) *zerolog.Logger
- func GetAuthPayload(c *gin.Context) (interface{}, bool)
- func InjectContextRequestHeader(ctx context.Context, req *http.Request)
- func NewAuthMiddleware(getToken IgetAuthToken, authenticator IAuthenticator) gin.HandlerFunc
- 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 CommonJwtAuthenticator
- type ContextMetaData
- type ContextMetaKey
- type CustomJwtAuthenticator
- type Error
- type HeaderAuthToken
- type IAuthenticator
- type IgetAuthToken
- type M2mClaims
- type M2mJwtAuthenticator
- type MyCustomClaims
- type PathSettings
- type QueryAuthToken
- type RequestLog
Constants ¶
View Source
const ( AuthPayload = "auth-payload" ACCESS_TOKEN_SUBJECT = "access_token" REFRESH_TOKEN_SUBJECT = "refresh_token" )
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 (
ErrorHeaderAuthFormat = errors.New("error header auth format")
)
View Source
var HeaderXRequestID string = "X-Request-ID"
Functions ¶
func AddRequestID ¶
func AddRequestID() gin.HandlerFunc
func GetAuthPayload ¶ added in v0.0.2
func NewAuthMiddleware ¶ added in v0.0.2
func NewAuthMiddleware(getToken IgetAuthToken, authenticator IAuthenticator) 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) ValidateAuth ¶
func (auth *AuthMiddleware) ValidateAuth() gin.HandlerFunc
type CommonJwtAuthenticator ¶ added in v0.0.3
type CommonJwtAuthenticator struct { Options []jwt.ParserOption JwtParse utils.IJwtParser }
func (*CommonJwtAuthenticator) Authenticate ¶ added in v0.0.3
func (auth *CommonJwtAuthenticator) Authenticate(token string) (interface{}, *Error)
type ContextMetaData ¶
func GetContextMetaData ¶
func GetContextMetaData(ctx context.Context) []ContextMetaData
GetContextMetaData get GetContextMetaData slice from incoming context
type ContextMetaKey ¶
type ContextMetaKey string
type CustomJwtAuthenticator ¶ added in v0.0.3
type CustomJwtAuthenticator struct { Audience string Issuer string Subject string JwtParse utils.IJwtParser }
func (*CustomJwtAuthenticator) Authenticate ¶ added in v0.0.3
func (auth *CustomJwtAuthenticator) Authenticate(token string) (interface{}, *Error)
type HeaderAuthToken ¶
func (*HeaderAuthToken) GetAuthToken ¶
func (h *HeaderAuthToken) GetAuthToken(r *http.Request) (string, error)
type IAuthenticator ¶
type IgetAuthToken ¶
func NewCustomGetAuthToken ¶ added in v0.0.3
func NewCustomGetAuthToken(fun func(*http.Request) (string, error)) IgetAuthToken
type M2mClaims ¶ added in v0.0.3
type M2mClaims struct { jwt.RegisteredClaims Scp string `json:"scp,omitempty"` }
type M2mJwtAuthenticator ¶ added in v0.0.3
type M2mJwtAuthenticator struct { Audience string Issuer string Scope string JwtParse utils.IJwtParser }
func (*M2mJwtAuthenticator) Authenticate ¶ added in v0.0.3
func (auth *M2mJwtAuthenticator) Authenticate(token string) (interface{}, *Error)
type MyCustomClaims ¶ added in v0.0.3
type MyCustomClaims struct { Uid string `json:"uid"` jwt.RegisteredClaims }
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.