Moritz Schmidt 9 jaren geleden
commit
367555041d
2 gewijzigde bestanden met toevoegingen van 35 en 0 verwijderingen
  1. 2 0
      README.md
  2. 33 0
      configutils.go

+ 2 - 0
README.md

@@ -0,0 +1,2 @@
+configutils
+===========

+ 33 - 0
configutils.go

@@ -0,0 +1,33 @@
+package configutils
+
+import (
+  "encoding/json"
+  "os"
+  "fmt"
+)
+
+var (
+  Conf *Configuration
+)
+
+type Configuration struct {
+    DBHost string
+    DBUser string
+    DBPass string
+    DBName string
+    CryptoKey string
+}
+
+func ReadConfig(filename string) Configuration {
+  file, _ := os.Open(filename)
+  decoder := json.NewDecoder(file)
+  configuration := Configuration{}
+  err := decoder.Decode(&configuration)
+  if err != nil {
+    fmt.Println("error:", err)
+  }
+
+  fmt.Printf("%#v", configuration)
+
+  return configuration
+}