summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/main.go b/main.go
index 952802a..edfe037 100644
--- a/main.go
+++ b/main.go
@@ -1,10 +1,14 @@
package main
import (
+ "errors"
"flag"
"html/template"
"log"
"net/http"
+ "os"
+ "path"
+ "strings"
"time"
)
@@ -71,10 +75,27 @@ func intervalUpdates(d time.Duration, stopch <-chan bool, chans ...chan<- bool)
}
}
+var tpl *template.Template
+
+func loadTemplate() {
+ gopaths := strings.Split(os.Getenv("GOPATH"), ":")
+ for _, p := range gopaths {
+ var err error
+ tpl, err = template.ParseFiles(path.Join(p, "src", "github.com", "kch42", "startpage", "template.html"))
+ if err == nil {
+ return
+ }
+ }
+
+ panic(errors.New("could not find template in $GOPATH/src/github.com/kch42/startpage"))
+}
+
func main() {
laddr := flag.String("laddr", ":25145", "Listen on this port")
flag.Parse()
+ loadTemplate()
+
pornch := make(chan bool)
weatherch := make(chan bool)
stopch := make(chan bool)
@@ -91,8 +112,6 @@ func main() {
log.Fatal(http.ListenAndServe(*laddr, nil))
}
-var tpl = template.Must(template.ParseFiles("template.html"))
-
type TplData struct {
Porn *EarthPorn
Weather *Weather