golib/gweb/requestid/options.go

42 lines
810 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 17:56:05 +08:00
import "git.hexq.cn/tiglog/golib/gweb"
2023-10-17 17:21:53 +08:00
// Option for queue system
type Option func(*config)
type (
Generator func() string
2023-10-17 17:56:05 +08:00
Handler func(c *gweb.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
}
}