Browse Source

Config: Move to subdirectory

master
Elis Hirwing 1 year ago
parent
commit
5ca25f0edd
Signed by: etu <elis@hirwing.se> GPG Key ID: D57EFA625C9A925F
7 changed files with 60 additions and 52 deletions
  1. +2
    -24
      main.go
  2. +49
    -0
      src/config/config.go
  3. +2
    -1
      statusscreen-clock.go
  4. +0
    -23
      statusscreen-config.go
  5. +3
    -2
      statusscreen-pollen.go
  6. +2
    -1
      statusscreen-sl.go
  7. +2
    -1
      statusscreen-weather.go

+ 2
- 24
main.go View File

@@ -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
- 0
src/config/config.go View File

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

+ 2
- 1
statusscreen-clock.go View File

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


+ 0
- 23
statusscreen-config.go View File

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

+ 3
- 2
statusscreen-pollen.go View File

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


+ 2
- 1
statusscreen-sl.go View File

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


+ 2
- 1
statusscreen-weather.go View File

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