initial commit
This commit is contained in:
41
internal/config/config.go
Normal file
41
internal/config/config.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Server ServerConfig `yaml:"server"`
|
||||
Devices []DeviceConfig `yaml:"devices"`
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
Port string `yaml:"port"`
|
||||
}
|
||||
|
||||
type DeviceConfig struct {
|
||||
Name string `yaml:"name"`
|
||||
Address string `yaml:"address"`
|
||||
Username string `yaml:"username"`
|
||||
Password string `yaml:"password"`
|
||||
Timeout string `yaml:"timeout"`
|
||||
SkipCollectors []string `yaml:"skip_collectors"`
|
||||
UpdateInterval string `yaml:"update_interval"` // например, "30s"
|
||||
CacheTTL string `yaml:"cache_ttl"` // например, "1m"
|
||||
}
|
||||
|
||||
func Load(path string) (*Config, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var config Config
|
||||
if err := yaml.Unmarshal(data, &config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
Reference in New Issue
Block a user