local-server/data.go

33 lines
704 B
Go
Raw Normal View History

2018-06-12 10:09:47 +00:00
package main
import (
"flag"
"log"
"path/filepath"
"novit.nc/direktil/pkg/clustersconfig"
)
var (
dataDir = flag.String("data", "/var/lib/direktil", "Data dir")
configFromDir = flag.String("config-from-dir", "", "Build configuration from this directory")
)
func readConfig() (config *clustersconfig.Config, err error) {
if *configFromDir != "" {
config, err = clustersconfig.FromDir(*dataDir)
if err != nil {
log.Print("failed to load config: ", err)
return nil, err
}
if err = config.SaveTo(filepath.Join(*dataDir, "global-config.yaml")); err != nil {
return nil, err
}
return
}
return clustersconfig.FromFile(filepath.Join(*dataDir, "current-config.yaml"))
}