46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package config
|
|
|
|
import (
|
|
"io"
|
|
|
|
yamlcodec "go.unistack.org/micro-codec-yaml/v3"
|
|
mtime "go.unistack.org/micro/v3/util/time"
|
|
)
|
|
|
|
type Meter struct {
|
|
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
|
Path string `json:"path,omitempty" yaml:"path,omitempty"`
|
|
}
|
|
|
|
type Config struct {
|
|
Meter *Meter `json:"meter,omitempty" yaml:"meter,omitempty"`
|
|
Checks []*Check `json:"checks,omitempty" yaml:"checks,omitempty"`
|
|
}
|
|
|
|
type Check struct {
|
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
|
Tasks []*Task `json:"tasks,omitempty" yaml:"tasks,omitempty"`
|
|
Timeout mtime.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
|
|
Interval mtime.Duration `json:"interval,omitempty" yaml:"interval,omitempty"`
|
|
}
|
|
|
|
type Task struct {
|
|
TLSVerify *bool `json:"tls_verify,omitempty" yaml:"tls_verify,omitempty"`
|
|
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
|
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
|
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
|
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
|
Protoset string `json:"protoset,omitempty" yaml:"protoset,omitempty"`
|
|
Timeout mtime.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
|
|
}
|
|
|
|
func (cfg *Config) Parse(r io.Reader) error {
|
|
buf, err := io.ReadAll(r)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return yamlcodec.NewCodec().Unmarshal(buf, cfg)
|
|
}
|