Первая реализация, добавил поддержку конфига

This commit is contained in:
B4D_US3R 2025-02-01 13:41:27 +05:00
parent f98a497c40
commit 1febae4ce4
6 changed files with 144 additions and 5 deletions

42
config/config.go Normal file
View file

@ -0,0 +1,42 @@
package config
import (
"log"
"os"
"gopkg.in/yaml.v3"
)
type target struct {
Instance string `yaml:"instance"`
UserID string `yaml:"userID"`
}
type exporter struct {
Listen string `yaml:"listen"`
Port string `yaml:"port"`
}
type InstanceVars struct {
Target target `yaml:"target"`
Exporter exporter `yaml:"exporter"`
}
func OpenFile(path string) []byte {
file, err := os.ReadFile(path)
if err != nil {
log.Println(err)
}
return file
}
func UnmYamlConfig(path string) InstanceVars {
fileContent := OpenFile(path)
var config InstanceVars
err := yaml.Unmarshal(fileContent, &config)
if err != nil {
log.Println(err)
}
return config
}