api/internal/config/parsing.go
Peter Kurfer 7c2a41ad25 Move TLS/cert handling to main app
- apply changes in proxy plugin and TLS interceptor
- add HTTPS proxy support
- move ca-generation command to main app
- minor refactoring to improve API stability
- move mocks to extra packages to avoid cycling imports
- fix bug in multi-port configuration
- change HTTP proxy to redirect to HTTP mock instead of maintaining custom rules
2020-04-26 00:32:46 +02:00

35 lines
845 B
Go

package config
import (
"github.com/spf13/viper"
)
const (
pluginConfigKey = "handler"
listenAddressConfigKey = "listenAddress"
portConfigKey = "port"
portsConfigKey = "ports"
)
func CreateMultiHandlerConfig(handlerConfig *viper.Viper) MultiHandlerConfig {
return NewMultiHandlerConfig(
handlerConfig.GetString(pluginConfigKey),
portsFromConfig(handlerConfig),
handlerConfig.GetString(listenAddressConfigKey),
handlerConfig.Sub(OptionsKey),
)
}
func portsFromConfig(handlerConfig *viper.Viper) (ports []uint16) {
if portsInt := handlerConfig.GetIntSlice(portsConfigKey); len(portsInt) > 0 {
for _, port := range portsInt {
ports = append(ports, uint16(port))
}
return
}
if portInt := handlerConfig.GetInt(portConfigKey); portInt > 0 {
ports = append(ports, uint16(portInt))
}
return
}