summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-12 00:12:55 +0200
committerxengineering <me@xengineering.eu>2024-05-12 00:12:55 +0200
commit642fed1cbf5160c89a93deab810bd44fb49d2a4a (patch)
treea676ee90aef8f67640af6ce49792782de33b3165
parent938ab103727688b73f2d7b3ef4d9e1b1c85c6628 (diff)
downloadceres-642fed1cbf5160c89a93deab810bd44fb49d2a4a.tar
ceres-642fed1cbf5160c89a93deab810bd44fb49d2a4a.tar.zst
ceres-642fed1cbf5160c89a93deab810bd44fb49d2a4a.zip
Move config path from config to flags struct
This is metadata about the config and thus does not belong to the config itself. Moving it to the struct holding flag values is straight forward since it is defined by flags.
-rw-r--r--config.go5
-rw-r--r--flags.go7
-rw-r--r--main.go4
3 files changed, 8 insertions, 8 deletions
diff --git a/config.go b/config.go
index 0527294..eabc8b0 100644
--- a/config.go
+++ b/config.go
@@ -11,7 +11,6 @@ import (
var defaultConfig string
type CeresConfig struct {
- Path string
HttpAddress string `json:"http_address"`
StorageFilePath string `json:"storage_file_path"`
}
@@ -25,8 +24,8 @@ func init() {
}
}
-func (c *CeresConfig) Read() {
- data, err := os.ReadFile(c.Path)
+func (c *CeresConfig) Read(path string) {
+ data, err := os.ReadFile(path)
if err != nil {
log.Fatal(err)
}
diff --git a/flags.go b/flags.go
index 1e802a1..a7a95e5 100644
--- a/flags.go
+++ b/flags.go
@@ -17,7 +17,8 @@ Usage: ceres [-h | --help] [-v | --version] [-c | --config]
`
var flags struct {
- version bool
+ version bool
+ config string
examples bool
}
@@ -25,8 +26,8 @@ func init() {
flag.BoolVar(&flags.version, "version", false, "print version information")
flag.BoolVar(&flags.version, "v", false, "print version information")
- flag.StringVar(&config.Path, "config", "", "file path to configuration file")
- flag.StringVar(&config.Path, "c", "", "file path to configuration file")
+ flag.StringVar(&flags.config, "config", "", "file path to configuration file")
+ flag.StringVar(&flags.config, "c", "", "file path to configuration file")
flag.BoolVar(&flags.examples, "examples", false, "inject example recipes on startup")
flag.BoolVar(&flags.examples, "e", false, "inject example recipes on startup")
diff --git a/main.go b/main.go
index 38fde52..b77c803 100644
--- a/main.go
+++ b/main.go
@@ -24,8 +24,8 @@ func main() {
defer log.Println("Ceres recipe server stopped")
log.Printf("Version: %s", version)
- if config.Path != "" {
- config.Read()
+ if flags.config != "" {
+ config.Read(flags.config)
}
storage := model.NewStorage(config.StorageFilePath)