summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2020-10-04 16:10:16 +0200
committerLaria Carolin Chabowski <laria@laria.me>2020-10-04 16:10:35 +0200
commit1a2ab41ae7140039c2fb2e5054038219c3e51da0 (patch)
treeef6313a9916c98633d401103ee7c08869346528d /main.go
parenta524bbdd3c7c84916ceb357fa6f83b4c8f98b82d (diff)
downloadstartpage-1a2ab41ae7140039c2fb2e5054038219c3e51da0.tar.gz
startpage-1a2ab41ae7140039c2fb2e5054038219c3e51da0.tar.bz2
startpage-1a2ab41ae7140039c2fb2e5054038219c3e51da0.zip
Move weather code into own package
Diffstat (limited to 'main.go')
-rw-r--r--main.go22
1 files changed, 17 insertions, 5 deletions
diff --git a/main.go b/main.go
index 4e2d25a..911fd13 100644
--- a/main.go
+++ b/main.go
@@ -11,10 +11,11 @@ import (
"path"
"strings"
"time"
+ "github.com/silvasur/startpage/weather"
)
var porn EarthPorn
-var weather Weather
+var curWeather weather.Weather
func trylater(ch chan<- bool) {
log.Println("Will try again later...")
@@ -36,16 +37,27 @@ func earthPornUpdater(ch chan bool) {
}
}
+var place = ""
+
+func setPlaceCmd(params []string) error {
+ if len(params) != 1 {
+ return errors.New("set-weather-place needs one parameter")
+ }
+
+ place = params[0]
+ return nil
+}
+
func weatherUpdater(ch chan bool) {
for _ = range ch {
- newW, err := CurrentWeather()
+ newW, err := weather.CurrentWeather(place)
if err != nil {
log.Printf("Failed getting latest weather data: %s", err)
go trylater(ch)
continue
}
- weather = newW
+ curWeather = newW
log.Println("New weather data")
}
}
@@ -138,14 +150,14 @@ func main() {
type TplData struct {
Porn *EarthPorn
- Weather *Weather
+ Weather *weather.Weather
Links []Link
}
func startpage(rw http.ResponseWriter, req *http.Request) {
defer req.Body.Close()
- if err := tpl.Execute(rw, &TplData{&porn, &weather, links}); err != nil {
+ if err := tpl.Execute(rw, &TplData{&porn, &curWeather, links}); err != nil {
log.Printf("Failed executing template: %s\n", err)
}
}