nurse/config/endpoints.go
Peter Kurfer 4c2aa968d2
Implement config reading
- support config file
- support reading checks, server definition and endpoint definitions from env
2022-05-08 11:00:22 +02:00

42 lines
662 B
Go

package config
import (
"encoding"
"fmt"
"path"
"strings"
"time"
"github.com/baez90/nurse/grammar"
)
var _ encoding.TextUnmarshaler = (*EndpointSpec)(nil)
type Route string
func (r Route) String() string {
val := string(r)
val = strings.Trim(val, "/")
return path.Clean(fmt.Sprintf("/%s", val))
}
type EndpointSpec struct {
CheckTimeout time.Duration
Checks []grammar.Check
}
func (e *EndpointSpec) UnmarshalText(text []byte) error {
parser, err := grammar.NewParser[grammar.Script]()
if err != nil {
return err
}
script, err := parser.Parse(string(text))
if err != nil {
return err
}
e.Checks = script.Checks
return nil
}