golib/gweb/requestid/options.go

42 lines
804 B
Go
Raw Normal View History

2023-10-17 17:21:53 +08:00
//
// options.go
// Copyright (C) 2023 tiglog <me@tiglog.com>
//
// Distributed under terms of the MIT license.
//
package requestid
2023-10-17 18:01:33 +08:00
import "github.com/gin-gonic/gin"
2023-10-17 17:21:53 +08:00
// Option for queue system
type Option func(*config)
type (
Generator func() string
2023-10-17 18:01:33 +08:00
Handler func(c *gin.Context, requestID string)
2023-10-17 17:21:53 +08:00
)
type HeaderStrKey string
// WithGenerator set generator function
func WithGenerator(g Generator) Option {
return func(cfg *config) {
cfg.generator = g
}
}
// WithCustomHeaderStrKey set custom header key for request id
func WithCustomHeaderStrKey(s HeaderStrKey) Option {
return func(cfg *config) {
cfg.headerKey = s
}
}
// WithHandler set handler function for request id with context
func WithHandler(handler Handler) Option {
return func(cfg *config) {
cfg.handler = handler
}
}