summaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-02-12 02:55:15 +0100
committerache <ache@ache.one>2019-02-12 02:55:15 +0100
commitb6584bff2ac111347f4db511f8ae65c87576811a (patch)
treee2cba8fd06a5cc06007bb965923481938b1c96d3 /server.go
parentInit commit (diff)
Handle Method
Diffstat (limited to 'server.go')
-rw-r--r--server.go31
1 files changed, 29 insertions, 2 deletions
diff --git a/server.go b/server.go
index 5b76fa3..29f6a05 100644
--- a/server.go
+++ b/server.go
@@ -6,11 +6,38 @@ import (
"net/http"
)
-func root( w http.ResponseWriter, r *http.Request) {
+func handleGet( w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "It's the root ! [%s]{{%s}}", r.URL.Path[1:], r.Method)
}
+func handlePost( w http.ResponseWriter, r *http.Request) {
+}
+func handleDelete( w http.ResponseWriter, r *http.Request) {
+}
+func handlePut( w http.ResponseWriter, r *http.Request) {
+}
+
+func handleMethod( w http.ResponseWriter, r *http.Request) {
+ switch r.Method {
+ case http.MethodGet:
+ handleGet(w, r)
+ case http.MethodPost:
+ handlePost(w, r)
+ case http.MethodPut:
+ handlePut(w, r)
+ case http.MethodDelete:
+ // Remove the record.
+ handleDelete(w, r)
+ default:
+ w.WriteHeader(http.StatusTeapot)
+ fmt.Fprintln(w, "Sry, i'm a teapot >///<")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, "Here's some tea. 🍵")
+ }
+}
func main() {
- http.HandleFunc("/", root)
+ fmt.Println("Launch server")
+ http.HandleFunc("/", handleMethod)
log.Fatal(http.ListenAndServe(":8080", nil))
+ fmt.Println("Bye bye")
}