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 mainTempl = template.Must(template.New("global").Funcs(template.FuncMap{"add": add}).ParseGlob("../views/*.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() insertHost() insertAdmin() 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) 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) http.Handle("/", r) ip := os.Getenv("STATUS_HTTP_IP") port := os.Getenv("STATUS_HTTP_PORT") http.ListenAndServe(ip+":"+port, nil) }