35 lines
783 B
Go
35 lines
783 B
Go
package Config
|
|
|
|
import (
|
|
"gopkg.in/yaml.v3"
|
|
"io/ioutil"
|
|
"rpiMqttControl/internal/MqttService"
|
|
"rpiMqttControl/internal/PinControlService"
|
|
)
|
|
|
|
type Config struct {
|
|
PinControlConfig PinControlService.PinControlConfig `yaml:"pin-control-config"`
|
|
MqttConfig MqttService.MqttServiceConfig `yaml:"mqtt-config"`
|
|
}
|
|
|
|
func NewConfig() Config {
|
|
return Config{
|
|
PinControlConfig: PinControlService.NewPinControlConfig(),
|
|
MqttConfig: MqttService.NewMqttServiceConfig(),
|
|
}
|
|
}
|
|
|
|
func NewConfigFromYamlFile(configFile string) (*Config, error) {
|
|
config := NewConfig()
|
|
if data, err := ioutil.ReadFile(configFile); err == nil {
|
|
if err := yaml.Unmarshal(data, &config); err == nil {
|
|
return &config, nil
|
|
} else {
|
|
return nil, err
|
|
}
|
|
} else {
|
|
return nil, err
|
|
}
|
|
|
|
}
|