42 lines
670 B
Go
42 lines
670 B
Go
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
|
|
}
|