summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.go14
-rw-r--r--flags.go9
-rw-r--r--main.go4
3 files changed, 25 insertions, 2 deletions
diff --git a/config.go b/config.go
index f97f2a3..0527294 100644
--- a/config.go
+++ b/config.go
@@ -4,12 +4,14 @@ import (
_ "embed"
"encoding/json"
"log"
+ "os"
)
//go:embed default_config.json
var defaultConfig string
type CeresConfig struct {
+ Path string
HttpAddress string `json:"http_address"`
StorageFilePath string `json:"storage_file_path"`
}
@@ -22,3 +24,15 @@ func init() {
log.Fatal(err)
}
}
+
+func (c *CeresConfig) Read() {
+ data, err := os.ReadFile(c.Path)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ err = json.Unmarshal(data, &c)
+ if err != nil {
+ log.Fatal(err)
+ }
+}
diff --git a/flags.go b/flags.go
index 862cffa..708e832 100644
--- a/flags.go
+++ b/flags.go
@@ -7,17 +7,22 @@ import (
const help = `Ceres - Recipe server for local networks
-Usage: ceres [-h | --help] [-v | --version]
+Usage: ceres [-h | --help] [-v | --version] [-c | --config]
-h, --help show this help page and exit
-v, --version print version information
+ -c, --config file path to configuration file
`
var printVersion bool
func init() {
flag.BoolVar(&printVersion, "version", false, "print version information")
- flag.BoolVar(&printVersion, "v", false, "print version information")
+ flag.BoolVar(&printVersion, "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.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), help)
}
diff --git a/main.go b/main.go
index d43edd2..4a45586 100644
--- a/main.go
+++ b/main.go
@@ -21,6 +21,10 @@ import (
func main() {
flag.Parse()
+ if config.Path != "" {
+ config.Read()
+ }
+
if printVersion {
if gitDescribe == "" {
log.Fatal("This build has no version information")