Documentation ¶
Index ¶
- Constants
- Variables
- func APILoggerMiddleware(logFile string) func(http.Handler) http.Handler
- func DefaultLoggerMiddleware(logFile string) func(http.Handler) http.Handler
- func GetMiddlewareLogger(ctx context.Context, logFile string) *httplog.Logger
- func GetStartTime(ctx context.Context) time.Time
- func GetTraceID(ctx context.Context) string
- func GetUserID(ctx context.Context) string
- func InitLogger(logFilePath string, name string) *httplog.Logger
- func InitLoggerBuffer(name string) (*httplog.Logger, *bytes.Buffer)
- func NextTraceID() uint64
- func ReadOnlyMode(next http.Handler) http.Handler
- func SubjectWhitelisted(subject, orgType, orgName string, whitelist []string) bool
- func Timing(next http.Handler) http.Handler
- func TokenAuthMiddleware(keyMap map[string]any, whitelist []string, logFilePath string) func(http.Handler) http.Handler
- func TraceID(next http.Handler) http.Handler
- func UserID(next http.Handler) http.Handler
Constants ¶
const ( TraceIDKey ctxKeyTraceID = 0 UserIDKey ctxKeyUserID = "user_id" )
TraceIDKey and UserIDKey are the keys that hold the unique trace ID and user ID in a request context.
Variables ¶
var ( APILoggerKey = &contextKey{"logger"} RunLoggerKey = &contextKey{"runLogger"} RunLoggerBufferKey = &contextKey{"runLoggerBuffer"} )
APILoggerKey is a context key used for associating a logger with a request.
var ( TraceIDHeader = "x-kusion-trace" UserIDHeader = "x-kusion-user" )
TraceIDHeader and UserIDHeader is the name of the HTTP Header which contains the trace id and user id.
var StartTimeKey = &contextKey{"startTime"}
StartTimeKey is a context key used for storing the start time of a request.
Functions ¶
func APILoggerMiddleware ¶ added in v0.13.0
APILoggerMiddleware injects a logger, configured with a request ID, into the request context for use throughout the request's lifecycle.
func DefaultLoggerMiddleware ¶ added in v0.13.0
DefaultLogger is a middleware that provides basic request logging using chi's built-in Logger middleware.
func GetMiddlewareLogger ¶ added in v0.13.0
func GetStartTime ¶
GetStartTime returns the start time from the given context if one is present. If the start time is not present or the context is nil, returns the zero time.
func GetTraceID ¶ added in v0.13.0
GetTraceID returns a trace ID from the given context if one is present. Returns the empty string if a trace ID cannot be found.
func GetUserID ¶ added in v0.13.0
GetUserID returns a user ID from the given context if one is present. Returns the empty string if a user ID cannot be found.
func InitLogger ¶ added in v0.13.0
func InitLoggerBuffer ¶ added in v0.14.0
func NextTraceID ¶ added in v0.13.0
func NextTraceID() uint64
NextTraceID generates the next trace ID in the sequence.
func ReadOnlyMode ¶
ReadOnlyMode disallows non-GET requests in read-only mode.
func SubjectWhitelisted ¶ added in v0.13.0
func Timing ¶
Timing is a middleware that captures the current time at the start of a request and stores it in the request context. This start time can be used to measure request processing duration.
func TokenAuthMiddleware ¶ added in v0.13.0
func TokenAuthMiddleware(keyMap map[string]any, whitelist []string, logFilePath string) func(http.Handler) http.Handler
This is the middleware function that verifies the JWT against a JWKS KeyMap
func TraceID ¶ added in v0.13.0
TraceID is a middleware that injects a trace ID into the context of each request. A trace ID is a string of the form "host.example.com/random-0001", where "random" is a base62 random string that uniquely identifies this go process, and where the last number is an atomically incremented request counter.
Types ¶
This section is empty.