|
@@ -1,34 +1,45 @@
|
|
|
package configutils
|
|
package configutils
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
- "encoding/json"
|
|
|
|
|
- "os"
|
|
|
|
|
- "fmt"
|
|
|
|
|
|
|
+ "encoding/json"
|
|
|
|
|
+ "log"
|
|
|
|
|
+ "os"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
var (
|
|
|
- Conf *Configuration // store configuration for global access
|
|
|
|
|
|
|
+ // Conf stores configuration for global access
|
|
|
|
|
+ Conf *Configuration
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+// Configuration defines the configuration structure
|
|
|
type Configuration struct {
|
|
type Configuration struct {
|
|
|
- DBHost string
|
|
|
|
|
- DBUser string
|
|
|
|
|
- DBPass string
|
|
|
|
|
- DBName string
|
|
|
|
|
- CryptoKey string
|
|
|
|
|
- // TODO dynamic fields
|
|
|
|
|
|
|
+ DBHost string
|
|
|
|
|
+ DBUser string
|
|
|
|
|
+ DBPass string
|
|
|
|
|
+ DBName string
|
|
|
|
|
+ CryptoKey string
|
|
|
|
|
+ ClientID string
|
|
|
|
|
+ ClientSecret string
|
|
|
|
|
+ CryptoStrength int
|
|
|
|
|
+ AuthURL string
|
|
|
|
|
+ // TODO dynamic fields, map string string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// ReadConfig reads the config file and returns a Configuration object
|
|
|
func ReadConfig(filename string) Configuration {
|
|
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)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ file, err := os.Open(filename)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ log.Println("Failed reading configuration:", err)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- //fmt.Printf("%#v", configuration) // DEBUG
|
|
|
|
|
|
|
+ decoder := json.NewDecoder(file)
|
|
|
|
|
+ configuration := Configuration{}
|
|
|
|
|
+ err = decoder.Decode(&configuration)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ log.Println("Failed parsing configuration:", err)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return configuration
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ //log.Printf("%#v", configuration) // DEBUG
|
|
|
|
|
+
|
|
|
|
|
+ return configuration
|
|
|
|
|
+}
|