|
@@ -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
|
|
|
|
|
+}
|