42 lines
810 B
Go
42 lines
810 B
Go
//
|
|
// options.go
|
|
// Copyright (C) 2023 tiglog <me@tiglog.com>
|
|
//
|
|
// Distributed under terms of the MIT license.
|
|
//
|
|
|
|
package requestid
|
|
|
|
import "git.hexq.cn/tiglog/golib/gweb"
|
|
|
|
// Option for queue system
|
|
type Option func(*config)
|
|
|
|
type (
|
|
Generator func() string
|
|
Handler func(c *gweb.Context, requestID string)
|
|
)
|
|
|
|
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
|
|
}
|
|
}
|