only respond to GET request

This commit is contained in:
dragongoose 2023-09-30 13:04:55 -04:00
parent a0c2a0c584
commit bb32647830
No known key found for this signature in database
GPG key ID: 01397EEC371CDAA5

11
main.go
View file

@ -28,14 +28,18 @@ func parseAndRenderTemplate(templateLocation string, data interface{}) (string,
var config scanner.Config = scanner.LoadConfig()
func rootPage(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
return
}
// get service status'
var data []scanner.ServiceStatus
for _, v := range config.Service {
data=append(data, scanner.TestService(v))
data = append(data, scanner.TestService(v))
}
log.Printf("%v", data)
parsedTemplate, err := parseAndRenderTemplate("templates/index.html.mustache", data)
if err != nil {
http.Error(w, err.Error(), 500)
@ -47,7 +51,6 @@ func rootPage(w http.ResponseWriter, r *http.Request) {
func main() {
http.HandleFunc("/", rootPage)
fmt.Printf("Listening on http://%v/\n", "localhost:3333")
log.Fatal(http.ListenAndServe(":3333", nil))
}