gohookr/config/config.go

35 lines
796 B
Go
Raw Normal View History

2021-08-04 11:04:01 +00:00
package config
// The struct that represents the config.json file
2021-08-04 11:04:01 +00:00
type Config struct {
ListenAddress string
Services map[string]struct {
Script Command
Secret string
2021-08-04 20:43:37 +00:00
SignaturePrefix string
2021-08-04 11:04:01 +00:00
SignatureHeader string
Tests []Command
}
}
// Check that all required fields are filled in
2021-08-04 11:04:01 +00:00
func (c Config) Validate() error {
if c.ListenAddress == "" {
return requiredFieldError{"ListenAddress", ""}
}
for serviceName, service := range c.Services {
if service.Script.Program == "" {
return requiredFieldError{"Script.Program", serviceName}
}
if service.SignatureHeader == "" {
return requiredFieldError{"SignatureHeader", serviceName}
}
if service.Secret == "" {
return requiredFieldError{"Secret", serviceName}
}
}
return nil
}