Gone with Rng, in comes a WIP form

Signed-off-by: Odyssey346 <odyssey346@disroot.org>
This commit is contained in:
Odyssey346
2022-07-26 12:57:30 +02:00
parent 1ccdfaf28a
commit 16983594f4
2 changed files with 24 additions and 0 deletions

22
api/form.go Normal file
View File

@ -0,0 +1,22 @@
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)
})
}