Browse Source

Config: Move to subdirectory

master
Elis Hirwing 2 years ago
parent
commit
5ca25f0edd
Signed by: etu GPG Key ID: D57EFA625C9A925F
  1. 26
      main.go
  2. 49
      src/config/config.go
  3. 3
      statusscreen-clock.go
  4. 23
      statusscreen-config.go
  5. 5
      statusscreen-pollen.go
  6. 3
      statusscreen-sl.go
  7. 3
      statusscreen-weather.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
}

49
src/config/config.go

@ -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
}

3
statusscreen-clock.go

@ -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

23
statusscreen-config.go

@ -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
}
}

5
statusscreen-pollen.go

@ -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" {

3
statusscreen-sl.go

@ -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
}

3
statusscreen-weather.go

@ -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…
Cancel
Save