Validate config parameters for random delay

- random-delay-max should not be less than random-delay-min
- random-delay-unit accepted values: s|ms
This commit is contained in:
Chris Loukas
2020-06-25 20:06:03 +03:00
parent 20a136a73c
commit f7d1c5639c
2 changed files with 14 additions and 1 deletions

View File

@@ -104,6 +104,20 @@ func main() {
viper.Set("port", strconv.Itoa(port))
}
// validate random delay options
if viper.GetInt("random-delay-max") < viper.GetInt("random-delay-min") {
logger.Panic("`--random-delay-max` should be greater than `--random-delay-min`")
}
switch delayUnit := viper.GetString("random-delay-unit"); delayUnit {
case
"s",
"ms":
break
default:
logger.Panic("`random-delay-unit` accepted values are: s|ms")
}
// load gRPC server config
var grpcCfg grpc.Config
if err := viper.Unmarshal(&grpcCfg); err != nil {

1
go.mod
View File

@@ -16,7 +16,6 @@ require (
github.com/gorilla/websocket v1.4.2
github.com/hashicorp/go-getter v1.4.1
github.com/prometheus/client_golang v1.5.1
github.com/prometheus/common v0.9.1
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.6.2