43 lines
833 B
Go
43 lines
833 B
Go
// config/config.go
|
|
package config
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type Config struct {
|
|
ScrapeInterval time.Duration `yaml:"scrape_interval"`
|
|
Readers []ReaderCfg `yaml:"readers"`
|
|
Exporters []ExporterCfg `yaml:"exporters"`
|
|
}
|
|
|
|
type ReaderCfg struct {
|
|
Type string `yaml:"type"`
|
|
Endpoint string `yaml:"endpoint,omitempty"`
|
|
Model string `yaml:"model,omitempty"`
|
|
}
|
|
|
|
type ExporterCfg struct {
|
|
Type string `yaml:"type"`
|
|
Addr string `yaml:"addr,omitempty"`
|
|
JSONFile string `yaml:"json_file,omitempty"`
|
|
}
|
|
|
|
func Load(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var c Config
|
|
if err := yaml.Unmarshal(data, &c); err != nil {
|
|
return nil, err
|
|
}
|
|
if c.ScrapeInterval == 0 {
|
|
c.ScrapeInterval = 5 * time.Second
|
|
}
|
|
return &c, nil
|
|
}
|