local-server/cmd/dkl-local-server/data.go

35 lines
702 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) {
2018-06-20 02:59:15 +00:00
configFile := filepath.Join(*dataDir, "current-config.yaml")
2018-06-12 10:09:47 +00:00
if *configFromDir != "" {
2018-06-20 02:59:15 +00:00
config, err = clustersconfig.FromDir(*configFromDir)
2018-06-12 10:09:47 +00:00
if err != nil {
log.Print("failed to load config: ", err)
return nil, err
}
2018-06-20 02:59:15 +00:00
if err = config.SaveTo(configFile); err != nil {
2018-06-12 10:09:47 +00:00
return nil, err
}
return
}
2018-06-20 02:59:15 +00:00
return clustersconfig.FromFile(configFile)
2018-06-12 10:09:47 +00:00
}