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-17 18:54:44 +03:00
|
|
|
type AppConfig struct {
|
2024-11-19 12:37:17 +03:00
|
|
|
ChecksDir string `json:"checks_dir,omitempty" yaml:"checks_dir,omitempty"`
|
|
|
|
Checks []*CheckConfig `json:"checks,omitempty" yaml:"checks,omitempty"`
|
|
|
|
MultiUser bool `json:"multi_user,omitempty" yaml:"multi_user,omitempty"`
|
2024-11-17 18:54:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type MeterConfig struct {
|
2024-11-16 20:17:37 +03:00
|
|
|
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-19 12:37:17 +03:00
|
|
|
App *AppConfig `json:"app,omitempty" yaml:"app,omitempty"`
|
|
|
|
Meter *MeterConfig `json:"meter,omitempty" yaml:"meter,omitempty"`
|
2024-11-15 19:04:48 +03:00
|
|
|
}
|
|
|
|
|
2024-11-17 18:54:44 +03:00
|
|
|
type CheckConfig struct {
|
2024-11-16 19:13:06 +03:00
|
|
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
2024-11-17 18:54:44 +03:00
|
|
|
Tasks []*TaskConfig `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-16 23:57:58 +03:00
|
|
|
Active bool `json:"active,omitempty" yaml:"active,omitempty"`
|
2024-11-17 19:33:05 +03:00
|
|
|
User string `json:"user,omitempty" yaml:"user,omitempty"`
|
2024-11-15 19:04:48 +03:00
|
|
|
}
|
|
|
|
|
2024-11-16 22:53:34 +03:00
|
|
|
type HTTPConfig struct {
|
2024-11-17 18:54:44 +03:00
|
|
|
Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
|
|
|
|
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
|
|
|
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
|
|
|
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
|
|
|
OpenAPI string `json:"openapi,omitempty" yaml:"openapi,omitempty"`
|
|
|
|
Method string `json:"method,omitempty" yaml:"method,omitempty"`
|
2024-11-16 22:53:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type GRPCConfig struct {
|
2024-11-17 18:54:44 +03:00
|
|
|
Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
|
|
|
|
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
|
|
|
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
|
|
|
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
|
|
|
Protoset string `json:"protoset,omitempty" yaml:"protoset,omitempty"`
|
2024-11-16 22:53:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type GraphQLConfig struct {
|
2024-11-17 18:54:44 +03:00
|
|
|
Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
|
|
|
|
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
|
|
|
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
|
|
|
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
2024-11-16 22:53:34 +03:00
|
|
|
}
|
|
|
|
|
2024-11-17 18:54:44 +03:00
|
|
|
type TaskConfig struct {
|
2024-11-16 22:53:34 +03:00
|
|
|
HTTP *HTTPConfig `json:"http,omitempty" yaml:"http,omitempty"`
|
|
|
|
GRPC *GRPCConfig `json:"grpc,omitempty" yaml:"grpc,omitempty"`
|
|
|
|
GraphQL *GraphQLConfig `json:"graphql,omitempty" yaml:"graphql"`
|
2024-11-16 19:57:00 +03:00
|
|
|
TLSVerify *bool `json:"tls_verify,omitempty" yaml:"tls_verify,omitempty"`
|
|
|
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
|
|
|
Timeout mtime.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
|
2024-11-16 23:57:58 +03:00
|
|
|
Active bool `json:"active,omitempty" yaml:"active,omitempty"`
|
2024-11-16 19:57:00 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|