diff --git a/api/form.go b/api/form.go new file mode 100644 index 0000000..81b8d9b --- /dev/null +++ b/api/form.go @@ -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) + }) +} \ No newline at end of file diff --git a/main.go b/main.go index e5efbac..17b5447 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "log" "github.com/ProjectSegfault/segfautilities/otherthings" "os" + "github.com/ProjectSegfault/segfautilities/api" ) type StaticThingy struct { @@ -31,6 +32,7 @@ func main() { http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "welcome to hell") }) + api.Form() log.Println("[HTTP] HTTP server is now running at " + pieceof + "!") log.Println(http.ListenAndServe(":" + pieceof, nil)) } \ No newline at end of file