summaryrefslogtreecommitdiff
path: root/utils/runtime_config.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-02-08 20:53:20 +0100
committerxengineering <me@xengineering.eu>2023-02-08 21:01:27 +0100
commitf9a5140071703faf0c7515a05f52e69fdc1f11ba (patch)
treeee073f3c7fc1a6bbda1eee6e3bec076e73363740 /utils/runtime_config.go
parent9005de11ef8b7cf32cc8503e8b5f134eca47b4fb (diff)
downloadceres-f9a5140071703faf0c7515a05f52e69fdc1f11ba.tar
ceres-f9a5140071703faf0c7515a05f52e69fdc1f11ba.tar.zst
ceres-f9a5140071703faf0c7515a05f52e69fdc1f11ba.zip
Move all sources to package main
This project is not so big that it needs multiple packages.
Diffstat (limited to 'utils/runtime_config.go')
-rw-r--r--utils/runtime_config.go65
1 files changed, 0 insertions, 65 deletions
diff --git a/utils/runtime_config.go b/utils/runtime_config.go
deleted file mode 100644
index fb5bd72..0000000
--- a/utils/runtime_config.go
+++ /dev/null
@@ -1,65 +0,0 @@
-
-package utils
-
-import (
- "fmt"
- "log"
- "flag"
- "os"
- "io/ioutil"
- "encoding/json"
-)
-
-type RuntimeConfig struct {
- Path string
- Http HttpConfig `json:"http"`
- Database DatabaseConfig `json:"database"`
-}
-
-type HttpConfig struct {
- Host string `json:"bind_host"`
- Port string `json:"bind_port"`
- Static string `json:"static"`
- Templates string `json:"templates"`
- Storage string `json:"storage"`
-}
-
-type DatabaseConfig struct {
- Socket string `json:"socket"`
- User string `json:"user"`
- Database string `json:"database"`
- Migrations string `json:"migrations"`
-}
-
-func GetRuntimeConfig() RuntimeConfig {
-
- // init empty return value
- config := RuntimeConfig{}
-
- // read command line flags
- flag.StringVar(&config.Path, "c", "/etc/ceres/config.json", "Path to ceres configuration file")
- flag.Parse()
-
- // open config file
- configFile, err := os.Open(config.Path)
- defer configFile.Close()
- if err != nil {
- log.Fatalf("Could not open configuration file %s", config.Path)
- }
-
- // read byte content
- configData, err := ioutil.ReadAll(configFile)
- if err != nil {
- log.Fatalf("Could not read configuration file %s", config.Path)
- }
-
- fmt.Print("Used config: " + string(configData) + "\n")
-
- // parse content to config structs
- err = json.Unmarshal(configData, &config)
- if err != nil {
- log.Fatalf("Could not parse configuration file %s", config.Path)
- }
-
- return config
-}