Gone with Rng, in comes a WIP form
Signed-off-by: Odyssey346 <odyssey346@disroot.org>
This commit is contained in:
parent
1ccdfaf28a
commit
16983594f4
22
api/form.go
Normal file
22
api/form.go
Normal 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)
|
||||||
|
})
|
||||||
|
}
|
2
main.go
2
main.go
@ -7,6 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"github.com/ProjectSegfault/segfautilities/otherthings"
|
"github.com/ProjectSegfault/segfautilities/otherthings"
|
||||||
"os"
|
"os"
|
||||||
|
"github.com/ProjectSegfault/segfautilities/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StaticThingy struct {
|
type StaticThingy struct {
|
||||||
@ -31,6 +32,7 @@ func main() {
|
|||||||
http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
io.WriteString(w, "welcome to hell")
|
io.WriteString(w, "welcome to hell")
|
||||||
})
|
})
|
||||||
|
api.Form()
|
||||||
log.Println("[HTTP] HTTP server is now running at " + pieceof + "!")
|
log.Println("[HTTP] HTTP server is now running at " + pieceof + "!")
|
||||||
log.Println(http.ListenAndServe(":" + pieceof, nil))
|
log.Println(http.ListenAndServe(":" + pieceof, nil))
|
||||||
}
|
}
|
Reference in New Issue
Block a user