mirror of
https://github.com/davidallendj/configurator.git
synced 2025-12-20 03:27:02 -07:00
refactor: changed log.Printf to log.Error in config
This commit is contained in:
parent
10ed21c5c1
commit
eda3cce177
1 changed files with 11 additions and 27 deletions
|
|
@ -1,10 +1,11 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
configurator "github.com/OpenCHAMI/configurator/pkg"
|
configurator "github.com/OpenCHAMI/configurator/pkg"
|
||||||
"github.com/OpenCHAMI/configurator/pkg/client"
|
"github.com/OpenCHAMI/configurator/pkg/client"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
|
@ -34,26 +35,9 @@ type Config struct {
|
||||||
// Creates a new config with default parameters.
|
// Creates a new config with default parameters.
|
||||||
func New() Config {
|
func New() Config {
|
||||||
return Config{
|
return Config{
|
||||||
Version: "",
|
Version: "",
|
||||||
SmdClient: client.SmdClient{Host: "http://127.0.0.1:27779"},
|
SmdClient: client.SmdClient{Host: "http://127.0.0.1:27779"},
|
||||||
Targets: map[string]configurator.Target{
|
Targets: map[string]configurator.Target{},
|
||||||
"dnsmasq": configurator.Target{
|
|
||||||
Plugin: "",
|
|
||||||
TemplatePaths: []string{},
|
|
||||||
},
|
|
||||||
"conman": configurator.Target{
|
|
||||||
Plugin: "",
|
|
||||||
TemplatePaths: []string{},
|
|
||||||
},
|
|
||||||
"warewulf": configurator.Target{
|
|
||||||
Plugin: "",
|
|
||||||
TemplatePaths: []string{
|
|
||||||
"templates/warewulf/defaults/node.jinja",
|
|
||||||
"templates/warewulf/defaults/provision.jinja",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
PluginDirs: []string{},
|
PluginDirs: []string{},
|
||||||
Server: Server{
|
Server: Server{
|
||||||
Host: "127.0.0.1:3334",
|
Host: "127.0.0.1:3334",
|
||||||
|
|
@ -69,12 +53,12 @@ func Load(path string) Config {
|
||||||
var c Config = New()
|
var c Config = New()
|
||||||
file, err := os.ReadFile(path)
|
file, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to read config file: %v\n", err)
|
log.Error().Err(err).Msg("failed to read config file")
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
err = yaml.Unmarshal(file, &c)
|
err = yaml.Unmarshal(file, &c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to unmarshal config: %v\n", err)
|
log.Error().Err(err).Msg("failed to unmarshal config")
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
|
|
@ -87,12 +71,12 @@ func (config *Config) Save(path string) {
|
||||||
}
|
}
|
||||||
data, err := yaml.Marshal(config)
|
data, err := yaml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to marshal config: %v\n", err)
|
log.Error().Err(err).Msg("failed to marshal config")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = os.WriteFile(path, data, os.ModePerm)
|
err = os.WriteFile(path, data, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to write default config file: %v\n", err)
|
log.Error().Err(err).Msg("failed to write default config file")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -105,12 +89,12 @@ func SaveDefault(path string) {
|
||||||
var c = New()
|
var c = New()
|
||||||
data, err := yaml.Marshal(c)
|
data, err := yaml.Marshal(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to marshal config: %v\n", err)
|
log.Error().Err(err).Msg("failed to marshal config")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = os.WriteFile(path, data, os.ModePerm)
|
err = os.WriteFile(path, data, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to write default config file: %v\n", err)
|
log.Error().Err(err).Msg("failed to write default config file")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue