Improve documentation and panic on invalid service

This commit is contained in:
TwinProduction
2020-04-14 20:13:06 -04:00
parent fe3e60dbd4
commit 2878ad6a27
3 changed files with 52 additions and 24 deletions

View File

@ -2,6 +2,7 @@ package core
import (
"bytes"
"errors"
"github.com/TwinProduction/gatus/client"
"io/ioutil"
"net"
@ -10,13 +11,18 @@ import (
"time"
)
var (
ErrNoCondition = errors.New("you must specify at least one condition per service")
ErrNoUrl = errors.New("you must specify an url for each service")
)
type Service struct {
Name string `yaml:"name"`
Interval time.Duration `yaml:"interval,omitempty"`
Url string `yaml:"url"`
Method string `yaml:"method,omitempty"`
Body string `yaml:"body,omitempty"`
Headers map[string]string `yaml:"headers"`
Headers map[string]string `yaml:"headers,omitempty"`
Interval time.Duration `yaml:"interval,omitempty"`
Conditions []*Condition `yaml:"conditions"`
}
@ -28,6 +34,15 @@ func (service *Service) Validate() {
if len(service.Method) == 0 {
service.Method = http.MethodGet
}
if len(service.Headers) == 0 {
service.Headers = make(map[string]string)
}
if len(service.Url) == 0 {
panic(ErrNoUrl)
}
if len(service.Conditions) == 0 {
panic(ErrNoCondition)
}
// Make sure that the request can be created
_, err := http.NewRequest(service.Method, service.Url, bytes.NewBuffer([]byte(service.Body)))