You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
850B

  1. package config
  2. import (
  3. "fmt"
  4. "github.com/BurntSushi/toml"
  5. "io/ioutil"
  6. "os"
  7. )
  8. // Config is a struct with my config
  9. type Config struct {
  10. SL struct {
  11. APIKey string
  12. RefreshDelay int64
  13. SiteID int
  14. APIURL string
  15. }
  16. Clock struct {
  17. TimeFormat string
  18. }
  19. Weather struct {
  20. URL string
  21. RefreshDelay int64
  22. }
  23. Pollen struct {
  24. URL string
  25. RefreshDelay int64
  26. CityName string
  27. }
  28. Watersensor struct {
  29. Host string
  30. RefreshDelay int64
  31. }
  32. }
  33. func New(configFile string) Config {
  34. var config Config
  35. // Read the configfile
  36. file, err := ioutil.ReadFile(configFile)
  37. if err != nil {
  38. fmt.Printf("File error: %v\n", err)
  39. os.Exit(1)
  40. }
  41. // Parse config
  42. if _, err := toml.Decode(string(file), &config); err != nil {
  43. fmt.Printf("Config error: %v\n", err)
  44. os.Exit(1)
  45. }
  46. return config
  47. }