diff --git a/api/announcements.go b/api/announcements.go index 4b37903..e23d30e 100644 --- a/api/announcements.go +++ b/api/announcements.go @@ -21,14 +21,24 @@ var ( func CheckAnn() { if resAnn == "true" { Announcements() + AnnPage() } else { log.Println("Announcements disabled") - http.HandleFunc("/api/announcements", func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc("/announcements", func(w http.ResponseWriter, r *http.Request) { http.Error(w, "Announcements are disabled.", http.StatusNotFound) }) + http.HandleFunc("/api/announcements", func(w http.ResponseWriter, r *http.Request) { + http.Error(w, "{\"enabled\": \"false\"}", http.StatusNotFound) + }) } } +func AnnPage() { + http.HandleFunc("/announcements", func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, "static/announcements.html") + }) +} + func Announcements() { http.HandleFunc("/api/announcements", getAnnouncements) http.HandleFunc("/api/announcements/post", handleAnnouncements) diff --git a/api/form.go b/api/form.go index 9edce97..42de194 100644 --- a/api/form.go +++ b/api/form.go @@ -6,6 +6,7 @@ import ( "log" "net/http" "net/url" + "text/template" "github.com/ProjectSegfault/segfautils/config" "github.com/ProjectSegfault/segfautils/utils" @@ -22,6 +23,7 @@ var ( func FormCheck() { if resForm == "true" { + FormPage() Form() } else { log.Println("Forms disabled") @@ -31,6 +33,22 @@ func FormCheck() { } } +func FormPage() { + type StaticThing struct { + HCaptchaSiteKey string + } + + tmpl_form := template.Must(template.ParseFiles("static/form.html")) + http.HandleFunc("/form/", func(w http.ResponseWriter, r *http.Request) { + + hcaptcha_site_key := config.HCaptchaSiteKey() + data := StaticThing{ + HCaptchaSiteKey: hcaptcha_site_key, + } + tmpl_form.Execute(w, data) + }) +} + func Form() { http.HandleFunc("/api/form", client.HandlerFunc(theActualFormCode)) } diff --git a/main.go b/main.go index c6f22de..ba01798 100644 --- a/main.go +++ b/main.go @@ -12,18 +12,13 @@ import ( ) type StaticThingy struct { - Port string - HCaptchaSiteKey string + Port string } -var port string -var shit bool - func main() { log.Println("[Segfautils] Starting") utils.CheckConfig() - log.Println("[HTTP] Starting server") - hcaptcha_site_key := config.HCaptchaSiteKey() + tmpl := template.Must(template.ParseFiles("static/index.html")) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { data := StaticThingy{ @@ -32,22 +27,15 @@ func main() { tmpl.Execute(w, data) }) - tmpl_form := template.Must(template.ParseFiles("static/form.html")) - http.HandleFunc("/form/", func(w http.ResponseWriter, r *http.Request) { - data := StaticThingy{ - HCaptchaSiteKey: hcaptcha_site_key, - } - tmpl_form.Execute(w, data) - }) + log.Println("[HTTP] Starting server") + api.CheckAnn() + api.FormCheck() http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "welcome to hell") }) - http.HandleFunc("/announcements", func(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "static/announcements.html") - }) - api.FormCheck() - api.CheckAnn() + + api.Form() log.Println("[HTTP] HTTP server is now running at " + config.Port() + "!") log.Println(http.ListenAndServe(":"+config.Port(), nil)) }