summaryrefslogtreecommitdiff
path: root/app/main.go
blob: 17d31576800a3f010a176ef68c0eba2f223f75ce (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
package main

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

var decoder = schema.NewDecoder()

var mainTempl = template.Must(template.New("global").ParseGlob("../views/*.html"))

var c = cron.New()

func main() {
	checkConfig()
	jobRun()
	InitDB()
	insertHost()

	r := mux.NewRouter()
	r.HandleFunc("/", IndexHandler)
	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("/jobs", ShowJobHandler)

	http.Handle("/", r)

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

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