Peter Kurfer
4c2aa968d2
- support config file - support reading checks, server definition and endpoint definitions from env
42 lines
662 B
Go
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
|
|
}
|