parent
31ef03fd6b
commit
5ca25f0edd
@ -0,0 +1,49 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/BurntSushi/toml"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Config is a struct with my config
|
||||
type Config struct {
|
||||
SL struct {
|
||||
APIKey string
|
||||
RefreshDelay int64
|
||||
SiteID int
|
||||
APIURL string
|
||||
}
|
||||
Clock struct {
|
||||
TimeFormat string
|
||||
}
|
||||
Weather struct {
|
||||
URL string
|
||||
RefreshDelay int64
|
||||
}
|
||||
Pollen struct {
|
||||
URL string
|
||||
RefreshDelay int64
|
||||
CityName string
|
||||
}
|
||||
}
|
||||
|
||||
func New(configFile string) Config {
|
||||
var config Config
|
||||
|
||||
// Read the configfile
|
||||
file, err := ioutil.ReadFile(configFile)
|
||||
if err != nil {
|
||||
fmt.Printf("File error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Parse config
|
||||
if _, err := toml.Decode(string(file), &config); err != nil {
|
||||
fmt.Printf("Config error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package main
|
||||
|
||||
// Config is a struct with my config
|
||||
type Config struct {
|
||||
SL struct {
|
||||
APIKey string
|
||||
RefreshDelay int64
|
||||
SiteID int
|
||||
APIURL string
|
||||
}
|
||||
Clock struct {
|
||||
TimeFormat string
|
||||
}
|
||||
Weather struct {
|
||||
URL string
|
||||
RefreshDelay int64
|
||||
}
|
||||
Pollen struct {
|
||||
URL string
|
||||
RefreshDelay int64
|
||||
CityName string
|
||||
}
|
||||
}
|
Loading…
Reference in new issue