summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/config.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/config/config.go b/config/config.go
new file mode 100644
index 0000000..691e756
--- /dev/null
+++ b/config/config.go
@@ -0,0 +1,46 @@
+package config
+
+import (
+ "encoding/json"
+ "io"
+ "os"
+)
+
+type Configuration struct {
+ Http struct {
+ ListenAddress string `json:"listen"`
+ BaseAddress string `json:"base"`
+ } `json:"http"`
+ Authentication struct {
+ Username string `json:"username"`
+ Password string `json:"password"`
+ } `json:"auth"`
+}
+
+func Must(config Configuration, err error) Configuration {
+ if err != nil {
+ panic(err)
+ }
+
+ return config
+}
+
+func Open(filename string) (Configuration, error) {
+ file, err := os.Open(filename)
+ if err != nil {
+ return Configuration{}, err
+ }
+
+ buf, err := io.ReadAll(file)
+ if err != nil {
+ return Configuration{}, err
+ }
+
+ config := Configuration{}
+
+ if err := json.Unmarshal(buf, &config); err != nil {
+ return Configuration{}, err
+ } else {
+ return config, nil
+ }
+}