Config: Move to subdirectory
parent
31ef03fd6b
commit
5ca25f0edd
26
main.go
26
main.go
|
@ -1,16 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/BurntSushi/toml"
|
||||
"./src/config"
|
||||
tm "github.com/buger/goterm"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
config := getConfig("status.toml")
|
||||
config := config.New("status.toml")
|
||||
|
||||
sl := SL{Config: &config}
|
||||
clock := Clock{Config: &config}
|
||||
|
@ -52,22 +49,3 @@ func main() {
|
|||
time.Sleep(time.Second / 10)
|
||||
}
|
||||
}
|
||||
|
||||
func getConfig(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
|
||||
}
|
||||
|
|
|
@ -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,13 +1,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"./src/config"
|
||||
"github.com/common-nighthawk/go-figure"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Clock is my Clock struct
|
||||
type Clock struct {
|
||||
Config *Config
|
||||
Config *config.Config
|
||||
}
|
||||
|
||||
// GetOutput returns a rendered result of this module
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"./src/config"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
|
@ -11,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
type Pollen struct {
|
||||
Config *Config
|
||||
Config *config.Config
|
||||
lastResponse PollenResponse
|
||||
nextRefresh int64
|
||||
}
|
||||
|
@ -77,7 +78,7 @@ func (pollen *Pollen) GetOutput() []string {
|
|||
|
||||
for _, v2 := range v.Pollen {
|
||||
// Drop rows that have the status: "inga halter" or "ingen rapport"
|
||||
if v2.Day0Description[:3] == "ing" &&
|
||||
if v2.Day0Description[:3] == "ing" &&
|
||||
v2.Day1Description[:3] == "ing" &&
|
||||
v2.Day2Description[:3] == "ing" &&
|
||||
v2.Day3Description[:3] == "ing" {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"./src/config"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
@ -15,7 +16,7 @@ import (
|
|||
|
||||
// SL is my SL struct
|
||||
type SL struct {
|
||||
Config *Config
|
||||
Config *config.Config
|
||||
lastResponse SLResponse
|
||||
nextRefresh int64
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"./src/config"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -9,7 +10,7 @@ import (
|
|||
|
||||
// Weather is my Weather struct
|
||||
type Weather struct {
|
||||
Config *Config
|
||||
Config *config.Config
|
||||
lastResponse string
|
||||
nextRefresh int64
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue