summaryrefslogtreecommitdiff
path: root/pkg/config/config.go
blob: 9fd58de93055fd473ae49a0ed2c200447aff1b83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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"`
}

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)
}