Inital
This commit is contained in:
32
config/config.go
Normal file
32
config/config.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// LoadConfig liest die YAML-Konfigurationsdatei und parst sie in ein Config-Struct.
|
||||
func loadConfig(path string) (*Config, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fehler beim Lesen der Datei: %w", err)
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
||||
return nil, fmt.Errorf("fehler beim Parsen der YAML-Daten: %w", err)
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
func GetConfig() (*Config, error) {
|
||||
config, err := loadConfig("misc/sample-config.yml")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read config: %w", err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
|
||||
}
|
||||
24
config/data.go
Normal file
24
config/data.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package config
|
||||
|
||||
// Config bildet die Struktur der YAML-Konfiguration ab.
|
||||
type Config struct {
|
||||
Defaults Defaults `yaml:"defaults"`
|
||||
Groups map[string]GroupDef `yaml:"groups"`
|
||||
}
|
||||
|
||||
// Defaults enthält Standardwerte.
|
||||
type Defaults struct {
|
||||
Temperatur int `yaml:"temperatur"`
|
||||
Dimming int `yaml:"dimming"`
|
||||
}
|
||||
|
||||
// GroupDef enthält die Details einer Gruppe, in diesem Fall eine Liste von Bulps.
|
||||
type GroupDef struct {
|
||||
Bulps []Bulp `yaml:"bulps"`
|
||||
}
|
||||
|
||||
// Bulp repräsentiert ein einzelnes Gerät.
|
||||
type Bulp struct {
|
||||
IP string `yaml:"ip"`
|
||||
Port string `yaml:"port"`
|
||||
}
|
||||
Reference in New Issue
Block a user