-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultipleVerbServer.go
More file actions
38 lines (31 loc) · 866 Bytes
/
multipleVerbServer.go
File metadata and controls
38 lines (31 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"log"
"net/http"
)
type server struct{}
func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch r.Method {
case "GET":
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"message": "Abhishek is writing his code GET Command"}`))
case "POST":
w.WriteHeader(http.StatusCreated)
w.Write([]byte(`{"message": "Abhishek is writing his code POST Command"}`))
case "PUT":
w.WriteHeader(http.StatusAccepted)
w.Write([]byte(`{"message": "Abhishek is writing his code "PUT Command"}`))
default:
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"message": "Abhishek is writing his code"}`))
}
fmt.Println("Response Out")
}
func main() {
s := &server{}
http.Handle("/", s)
log.Println("Startign server")
log.Fatal(http.ListenAndServe(":8000", nil))
}