Первая реализация, добавил поддержку конфига
This commit is contained in:
parent
f98a497c40
commit
1febae4ce4
6 changed files with 144 additions and 5 deletions
42
config/config.go
Normal file
42
config/config.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue