configutils.go 592 B

12345678910111213141516171819202122232425262728293031323334
  1. package configutils
  2. import (
  3. "encoding/json"
  4. "os"
  5. "fmt"
  6. )
  7. var (
  8. Conf *Configuration // store configuration for global access
  9. )
  10. type Configuration struct {
  11. DBHost string
  12. DBUser string
  13. DBPass string
  14. DBName string
  15. CryptoKey string
  16. // TODO dynamic fields
  17. }
  18. func ReadConfig(filename string) Configuration {
  19. file, _ := os.Open(filename)
  20. decoder := json.NewDecoder(file)
  21. configuration := Configuration{}
  22. err := decoder.Decode(&configuration)
  23. if err != nil {
  24. fmt.Println("error:", err)
  25. }
  26. //fmt.Printf("%#v", configuration) // DEBUG
  27. return configuration
  28. }