diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-07 15:58:04 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-07 15:58:04 -0700 |
| commit | 041c2df698d4702816cf8472d212553d289a2c0c (patch) | |
| tree | 4b461b916462bbf0909c50081aa899373e0aaffb /hotline | |
| parent | 7c7c1f63412ead526ff7bf9e029591c50aefabf7 (diff) | |
Add initial validations of config.yaml
Diffstat (limited to 'hotline')
| -rw-r--r-- | hotline/config.go | 22 | ||||
| -rw-r--r-- | hotline/server.go | 7 |
2 files changed, 18 insertions, 11 deletions
diff --git a/hotline/config.go b/hotline/config.go index d2a8ac6..cd1d850 100644 --- a/hotline/config.go +++ b/hotline/config.go @@ -1,15 +1,15 @@ package hotline type Config struct { - Name string `yaml:"Name"` // Name used for Tracker registration - Description string `yaml:"Description"` // Description used for Tracker registration - BannerID int `yaml:"BannerID"` // Unimplemented - FileRoot string `yaml:"FileRoot"` // Path to Files - EnableTrackerRegistration bool `yaml:"EnableTrackerRegistration"` // Toggle Tracker Registration - Trackers []string `yaml:"Trackers"` // List of trackers that the server should register with - NewsDelimiter string `yaml:"NewsDelimiter"` // String used to separate news posts - NewsDateFormat string `yaml:"NewsDateFormat"` // Go template string to customize news date format - MaxDownloads int `yaml:"MaxDownloads"` // Global simultaneous download limit - MaxDownloadsPerClient int `yaml:"MaxDownloadsPerClient"` // Per client simultaneous download limit - MaxConnectionsPerIP int `yaml:"MaxConnectionsPerIP"` // Max connections per IP + Name string `yaml:"Name" validate:"required,max=50"` // Name used for Tracker registration + Description string `yaml:"Description" validate:"required,max=200"` // Description used for Tracker registration + BannerID int `yaml:"BannerID"` // Unimplemented + FileRoot string `yaml:"FileRoot" validate:"required"` // Path to Files + EnableTrackerRegistration bool `yaml:"EnableTrackerRegistration"` // Toggle Tracker Registration + Trackers []string `yaml:"Trackers" validate:"dive,hostname_port"` // List of trackers that the server should register with + NewsDelimiter string `yaml:"NewsDelimiter"` // String used to separate news posts + NewsDateFormat string `yaml:"NewsDateFormat"` // Go template string to customize news date format + MaxDownloads int `yaml:"MaxDownloads"` // Global simultaneous download limit + MaxDownloadsPerClient int `yaml:"MaxDownloadsPerClient"` // Per client simultaneous download limit + MaxConnectionsPerIP int `yaml:"MaxConnectionsPerIP"` // Max connections per IP } diff --git a/hotline/server.go b/hotline/server.go index fb06001..e6322e0 100644 --- a/hotline/server.go +++ b/hotline/server.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "errors" "fmt" + "github.com/go-playground/validator/v10" "go.uber.org/zap" "io" "io/fs" @@ -477,6 +478,12 @@ func (s *Server) loadConfig(path string) error { if err != nil { return err } + + validate := validator.New() + err = validate.Struct(s.Config) + if err != nil { + return err + } return nil } |