2024-11-15 19:04:48 +03:00
|
|
|
package config
|
|
|
|
|
2024-11-16 15:21:52 +03:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
mtime "go.unistack.org/micro/v3/util/time"
|
|
|
|
yaml "gopkg.in/yaml.v3"
|
|
|
|
)
|
2024-11-15 19:04:48 +03:00
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Services []*Service `json:"services,omitempty" yaml:"services,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Service struct {
|
2024-11-16 15:21:52 +03:00
|
|
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
|
|
|
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
|
|
|
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
|
|
|
Reflection bool `json:"reflection,omitempty" yaml:"reflection,omitempty"`
|
|
|
|
Protoset string `json:"protoset,omitempty" yaml:"protoset,omitempty"`
|
|
|
|
Checks []*Check `json:"checks,omitempty" yaml:"checks,omitempty"`
|
|
|
|
TLSVerify *bool `json:"tls_verify,omitempty" yaml:"tls_verify,omitempty"`
|
2024-11-15 19:04:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Check struct {
|
2024-11-16 15:21:52 +03:00
|
|
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
|
|
|
Data string `json:"data,omitempty" yaml:"data,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
|
|
|
|
}
|
|
|
|
|
|
|
|
return yaml.Unmarshal(buf, cfg)
|
|
|
|
}
|