2020-04-01 02:08:21 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import "github.com/spf13/viper"
|
|
|
|
|
|
|
|
const (
|
|
|
|
pluginConfigKey = "handler"
|
2020-04-13 22:14:56 +00:00
|
|
|
listenAddressConfigKey = "listenAddress"
|
2020-04-01 02:08:21 +00:00
|
|
|
portConfigKey = "port"
|
2020-04-13 22:14:56 +00:00
|
|
|
portsConfigKey = "ports"
|
2020-04-01 02:08:21 +00:00
|
|
|
)
|
|
|
|
|
2020-04-13 22:14:56 +00:00
|
|
|
type HandlerConfig interface {
|
|
|
|
HandlerName() string
|
|
|
|
ListenAddress() string
|
|
|
|
Port() uint16
|
|
|
|
Options() *viper.Viper
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHandlerConfig(handlerName string, port uint16, listenAddress string, options *viper.Viper) HandlerConfig {
|
|
|
|
return &handlerConfig{
|
|
|
|
handlerName: handlerName,
|
|
|
|
port: port,
|
|
|
|
listenAddress: listenAddress,
|
|
|
|
options: options,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 02:08:21 +00:00
|
|
|
type handlerConfig struct {
|
2020-04-13 22:14:56 +00:00
|
|
|
handlerName string
|
2020-04-01 02:08:21 +00:00
|
|
|
port uint16
|
|
|
|
listenAddress string
|
|
|
|
options *viper.Viper
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h handlerConfig) HandlerName() string {
|
2020-04-13 22:14:56 +00:00
|
|
|
return h.handlerName
|
2020-04-01 02:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h handlerConfig) ListenAddress() string {
|
|
|
|
return h.listenAddress
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h handlerConfig) Port() uint16 {
|
|
|
|
return h.port
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h handlerConfig) Options() *viper.Viper {
|
|
|
|
return h.options
|
|
|
|
}
|