energyd/internal/config/config.go
2023-02-27 19:06:25 -05:00

32 lines
708 B
Go

package config
import (
"fmt"
"github.com/spf13/viper"
)
type Conf struct {
ISOUser string
ISOPassword string
NoVerifyCert bool
}
func Config() *Conf {
viper.SetConfigName("energyd")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("fatal error config file: %w", err))
}
noVerifyCert := false
if nVC, exists := viper.Get("iso.noVerifyCert").(bool); exists {
noVerifyCert = nVC
}
return &Conf{
ISOUser: viper.Get("iso.user").(string),
ISOPassword: viper.Get("iso.password").(string),
NoVerifyCert: noVerifyCert,
}
}