This repository has been archived on 2022-10-30. You can view files and clone it, but cannot push or open issues or pull requests.
Segfautils/api/form.go
Odyssey346 16983594f4 Gone with Rng, in comes a WIP form
Signed-off-by: Odyssey346 <odyssey346@disroot.org>
2022-07-26 12:57:30 +02:00

22 lines
566 B
Go

package api
import (
"net/http"
"io"
"log"
)
func Form() {
http.HandleFunc("/api/form", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
io.WriteString(w, "I got your ")
io.WriteString(w, "\n" + r.RemoteAddr)
case http.MethodPost:
io.WriteString(w, "You have no mail to POST!")
default:
http.Error(w, "Method isn't allowed!\nYou may only GET or POST here, not " + r.Method, http.StatusMethodNotAllowed)
}
log.Println("[HTTP] " + r.RemoteAddr + " accessed /api/form with method " + r.Method)
})
}