2024-11-15 19:04:48 +03:00
|
|
|
package config
|
|
|
|
|
2024-11-16 15:21:52 +03:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2024-11-16 20:17:37 +03:00
|
|
|
yamlcodec "go.unistack.org/micro-codec-yaml/v3"
|
2024-11-16 15:21:52 +03:00
|
|
|
mtime "go.unistack.org/micro/v3/util/time"
|
|
|
|
)
|
2024-11-15 19:04:48 +03:00
|
|
|
|
2024-11-16 20:17:37 +03:00
|
|
|
type Meter struct {
|
|
|
|
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
|
|
|
Path string `json:"path,omitempty" yaml:"path,omitempty"`
|
|
|
|
}
|
|
|
|
|
2024-11-15 19:04:48 +03:00
|
|
|
type Config struct {
|
2024-11-16 20:17:37 +03:00
|
|
|
Meter *Meter `json:"meter,omitempty" yaml:"meter,omitempty"`
|
2024-11-16 19:57:00 +03:00
|
|
|
Checks []*Check `json:"checks,omitempty" yaml:"checks,omitempty"`
|
2024-11-15 19:04:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Check struct {
|
2024-11-16 19:13:06 +03:00
|
|
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
2024-11-16 19:57:00 +03:00
|
|
|
Tasks []*Task `json:"tasks,omitempty" yaml:"tasks,omitempty"`
|
2024-11-16 19:13:06 +03:00
|
|
|
Timeout mtime.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
|
|
|
|
Interval mtime.Duration `json:"interval,omitempty" yaml:"interval,omitempty"`
|
2024-11-15 19:04:48 +03:00
|
|
|
}
|
|
|
|
|
2024-11-16 19:57:00 +03:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2024-11-15 19:04:48 +03:00
|
|
|
func (cfg *Config) Parse(r io.Reader) error {
|
|
|
|
buf, err := io.ReadAll(r)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-11-16 20:17:37 +03:00
|
|
|
return yamlcodec.NewCodec().Unmarshal(buf, cfg)
|
2024-11-15 19:04:48 +03:00
|
|
|
}
|