59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package proxy
|
|
|
|
import (
|
|
"time"
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/config"
|
|
"forge.cadoles.com/cadoles/bouncer/internal/proxy/director"
|
|
"forge.cadoles.com/cadoles/bouncer/internal/store"
|
|
)
|
|
|
|
type Option struct {
|
|
ServerConfig config.ProxyServerConfig
|
|
DirectorLayers []director.Layer
|
|
DirectorCacheTTL time.Duration
|
|
|
|
ProxyRepository store.ProxyRepository
|
|
LayerRepository store.LayerRepository
|
|
}
|
|
|
|
type OptionFunc func(*Option)
|
|
|
|
func defaultOption() *Option {
|
|
return &Option{
|
|
ServerConfig: config.NewDefaultProxyServerConfig(),
|
|
DirectorLayers: make([]director.Layer, 0),
|
|
DirectorCacheTTL: 30 * time.Second,
|
|
}
|
|
}
|
|
|
|
func WithServerConfig(conf config.ProxyServerConfig) OptionFunc {
|
|
return func(opt *Option) {
|
|
opt.ServerConfig = conf
|
|
}
|
|
}
|
|
|
|
func WithDirectorLayers(layers ...director.Layer) OptionFunc {
|
|
return func(opt *Option) {
|
|
opt.DirectorLayers = layers
|
|
}
|
|
}
|
|
|
|
func WithDirectorCacheTTL(ttl time.Duration) OptionFunc {
|
|
return func(opt *Option) {
|
|
opt.DirectorCacheTTL = ttl
|
|
}
|
|
}
|
|
|
|
func WithLayerRepository(layerRepository store.LayerRepository) OptionFunc {
|
|
return func(opt *Option) {
|
|
opt.LayerRepository = layerRepository
|
|
}
|
|
}
|
|
|
|
func WithProxyRepository(proxyRepository store.ProxyRepository) OptionFunc {
|
|
return func(opt *Option) {
|
|
opt.ProxyRepository = proxyRepository
|
|
}
|
|
}
|