summaryrefslogtreecommitdiff
path: root/app/main.go
blob: f4bddda1a895660030fdb76deb066d923a037afc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main

import (
	"github.com/gorilla/mux"
	"github.com/gorilla/schema"
	"github.com/gorilla/sessions"
	"github.com/robfig/cron"
	"html/template"
	"log"
	"net/http"
	"os"
)

var decoder = schema.NewDecoder()

//var store = sessions.NewCookieStore([]byte(RandomKey()))
var store = sessions.NewCookieStore([]byte(os.Getenv("STATUS_SECRET")))

var mainTempl = template.Must(template.New("global").Funcs(template.FuncMap{"add": add}).ParseGlob("../views/*.html"))
var emailTempl = template.Must(template.New("email").Funcs(template.FuncMap{"add": add}).ParseGlob("../views/email/*.html"))

var c = cron.New()

func add(x, y int) int {
	return x + y
}

func main() {
	decoder.IgnoreUnknownKeys(true)
	store.Options = &sessions.Options{
		Path:     "/",
		MaxAge:   86400,
		HttpOnly: true,
	}
	checkConfig()
	jobRun()
	InitDB()
	go func() {
		err := FillCache()
		if err != nil {
			log.Panic(err)
		}
	}()

	r := mux.NewRouter()
	r.HandleFunc("/", IndexHandler)
	r.HandleFunc("/login", LoginHandler).Methods("POST")
	r.HandleFunc("/login", PrintLoginHandler).Methods("GET")
	r.HandleFunc("/logout", LogoutHandler).Methods("POST")
	r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./../static"))))
	r.HandleFunc("/register", RegisterHandler).Methods("POST")
	//r.HandleFunc("/register", PrintRegisterHandler).Methods("GET")
	r.HandleFunc("/new", AddNewJobHandler).Methods("POST")
	//r.HandleFunc("/new", PrintNewJobHandler).Methods("GET")
	r.HandleFunc("/refresh", RefreshAllHandler).Methods("POST")
	//r.HandleFunc("/jobs", ShowJobHandler)
	r.HandleFunc("/admin", AdminHandler)
	r.HandleFunc("/register", SetupHandler)
	//r.HandleFunc("/delete", DeleteHandler).Methods("POST")
	r.HandleFunc("/delete", DeleteHandler)
	r.HandleFunc("/sticky/new", NewStickyHandler).Methods("POST")

	http.Handle("/", r)

	ip := os.Getenv("STATUS_HTTP_IP")
	port := os.Getenv("STATUS_HTTP_PORT")

	http.ListenAndServe(ip+":"+port, nil)
}