2023-04-24 20:52:12 +02:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
2024-05-28 16:45:15 +02:00
|
|
|
"time"
|
|
|
|
|
2023-04-24 20:52:12 +02:00
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/config"
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/proxy/director"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Option struct {
|
2024-05-28 16:45:15 +02:00
|
|
|
ServerConfig config.ProxyServerConfig
|
|
|
|
RedisConfig config.RedisConfig
|
|
|
|
DirectorLayers []director.Layer
|
|
|
|
DirectorCacheTTL time.Duration
|
2023-04-24 20:52:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type OptionFunc func(*Option)
|
|
|
|
|
|
|
|
func defaultOption() *Option {
|
|
|
|
return &Option{
|
2024-05-28 16:45:15 +02:00
|
|
|
ServerConfig: config.NewDefaultProxyServerConfig(),
|
|
|
|
RedisConfig: config.NewDefaultRedisConfig(),
|
|
|
|
DirectorLayers: make([]director.Layer, 0),
|
|
|
|
DirectorCacheTTL: 30 * time.Second,
|
2023-04-24 20:52:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithServerConfig(conf config.ProxyServerConfig) OptionFunc {
|
|
|
|
return func(opt *Option) {
|
|
|
|
opt.ServerConfig = conf
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithRedisConfig(conf config.RedisConfig) OptionFunc {
|
|
|
|
return func(opt *Option) {
|
|
|
|
opt.RedisConfig = conf
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithDirectorLayers(layers ...director.Layer) OptionFunc {
|
|
|
|
return func(opt *Option) {
|
|
|
|
opt.DirectorLayers = layers
|
|
|
|
}
|
|
|
|
}
|
2024-05-28 16:45:15 +02:00
|
|
|
|
|
|
|
func WithDirectorCacheTTL(ttl time.Duration) OptionFunc {
|
|
|
|
return func(opt *Option) {
|
|
|
|
opt.DirectorCacheTTL = ttl
|
|
|
|
}
|
|
|
|
}
|