mirror of
https://github.com/alvierahman90/gohookr.git
synced 2026-01-26 23:24:00 +00:00
Move config to separate package
This commit is contained in:
39
config/config.go
Normal file
39
config/config.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ListenAddress string
|
||||
Services map[string]struct {
|
||||
Script Command
|
||||
Secret string
|
||||
SignatureHeader string
|
||||
Tests []Command
|
||||
}
|
||||
}
|
||||
|
||||
func (c Config) Validate() error {
|
||||
if c.ListenAddress == "" {
|
||||
return requiredFieldError{"ListenAddress", ""}
|
||||
}
|
||||
|
||||
jsonbytes, _ := json.MarshalIndent(c, "", " ")
|
||||
fmt.Println(string(jsonbytes))
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user