idecnode/pkg/config/config.go

38 lines
769 B
Go
Raw Permalink Normal View History

2024-10-20 03:39:07 +03:00
package config
import (
"os"
"gopkg.in/yaml.v3"
)
type Config struct {
Listen string `yaml:"listen"`
Node string `yaml:"node"`
Store string `yaml:"store"`
LoggerType int `yaml:"logger_type"`
Echos map[string]Echo `yaml:"echos"`
Fetch []Node `yaml:"fetch"`
FilesDirectory string `yaml:"files_directory"`
2024-10-20 03:39:07 +03:00
}
type Node struct {
Addr string `yaml:"addr"`
Echos []string `yaml:"echos"`
}
type Echo struct {
Description string `yaml:"description"`
}
func New(filePath string) (*Config, error) {
cfg := new(Config)
fp, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer fp.Close()
return cfg, yaml.NewDecoder(fp).Decode(cfg)
}