2020-06-10 20:47:35 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/consul/agent/pool"
|
2020-08-27 15:23:52 +00:00
|
|
|
"github.com/hashicorp/consul/agent/router"
|
2020-06-10 20:47:35 +00:00
|
|
|
"github.com/hashicorp/consul/agent/token"
|
|
|
|
"github.com/hashicorp/consul/tlsutil"
|
|
|
|
"github.com/hashicorp/go-hclog"
|
|
|
|
)
|
|
|
|
|
|
|
|
type consulOptions struct {
|
|
|
|
logger hclog.InterceptLogger
|
|
|
|
tlsConfigurator *tlsutil.Configurator
|
|
|
|
connPool *pool.ConnPool
|
|
|
|
tokens *token.Store
|
2020-08-27 15:23:52 +00:00
|
|
|
router *router.Router
|
2020-06-10 20:47:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ConsulOption func(*consulOptions)
|
|
|
|
|
|
|
|
func WithLogger(logger hclog.InterceptLogger) ConsulOption {
|
|
|
|
return func(opt *consulOptions) {
|
|
|
|
opt.logger = logger
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithTLSConfigurator(tlsConfigurator *tlsutil.Configurator) ConsulOption {
|
|
|
|
return func(opt *consulOptions) {
|
|
|
|
opt.tlsConfigurator = tlsConfigurator
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithConnectionPool(connPool *pool.ConnPool) ConsulOption {
|
|
|
|
return func(opt *consulOptions) {
|
|
|
|
opt.connPool = connPool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithTokenStore(tokens *token.Store) ConsulOption {
|
|
|
|
return func(opt *consulOptions) {
|
|
|
|
opt.tokens = tokens
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-27 15:23:52 +00:00
|
|
|
func WithRouter(router *router.Router) ConsulOption {
|
|
|
|
return func(opt *consulOptions) {
|
|
|
|
opt.router = router
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 20:47:35 +00:00
|
|
|
func flattenConsulOptions(options []ConsulOption) consulOptions {
|
|
|
|
var flat consulOptions
|
|
|
|
for _, opt := range options {
|
|
|
|
opt(&flat)
|
|
|
|
}
|
|
|
|
return flat
|
|
|
|
}
|