package main import ( "net/http" "os" "html/template" "log" ) var templates = template.Must(template.ParseGlob("*.html")) func main() { mode := os.Getenv("DEBUG_MODE") if mode == "true" { log.Println("Debug mode is on") } http.HandleFunc("/imprint", imprint) http.HandleFunc("/about", about) http.HandleFunc("/", homepage) http.HandleFunc("/monitoring", monitoring) log.Fatal(http.ListenAndServe(":8080", nil)) } func imprint(w http.ResponseWriter, r *http.Request) { renderTemplate(w, "imprint.html") } func about(w http.ResponseWriter, r *http.Request) { renderTemplate(w, "about.html") } func homepage(w http.ResponseWriter, r *http.Request) { renderTemplate(w, "homepage.html") } func monitoring(w http.ResponseWriter, r *http.Request) { gitURL := os.Getenv("GIT_URL") websiteURL := os.Getenv("WEBSITE_URL") gitStatus := getStatus(gitURL) websiteStatus := getStatus(websiteURL) data := struct { GitStatus string WebsiteStatus string }{ GitStatus: gitStatus, WebsiteStatus: websiteStatus, } renderTemplate(w, "monitoring.html", data) } func renderTemplate(w http.ResponseWriter, tmpl string, data ...interface{}) { err := templates.ExecuteTemplate(w, tmpl, data) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } } func getStatus(link string) string { resp, err := http.Get(link) if err != nil { return "OFFLINE" } defer resp.Body.Close() if resp.StatusCode == 200 { return "ONLINE" } return "ERROR" }