File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed
Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change 44 "log"
55 "net/http"
66
7+ "github.com/gorilla/mux"
78 _ "github.com/lib/pq"
89)
910
@@ -15,16 +16,20 @@ import (
1516
1617// }
1718
18- type server struct {}
19-
20- func (s * server ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
19+ func home (w http.ResponseWriter , r * http.Request ) {
2120 w .Header ().Set ("Content-Type" , "application/json" )
22- w .WriteHeader (http .StatusOK )
23- w .Write ([]byte (`{"message": "hello world"}` ))
21+ switch r .Method {
22+ case "GET" :
23+ w .WriteHeader (http .StatusOK )
24+ w .Write ([]byte (`{"message": "get called"}` ))
25+ case "POST" :
26+ w .WriteHeader (http .StatusCreated )
27+ w .Write ([]byte (`{"message": "post called"}` ))
28+ }
2429}
2530
2631func main () {
27- s := & server {}
28- http . Handle ("/" , s )
29- log .Fatal (http .ListenAndServe (":8080" , nil ))
32+ r := mux . NewRouter ()
33+ r . HandleFunc ("/" , home )
34+ log .Fatal (http .ListenAndServe (":8080" , r ))
3035}
You can’t perform that action at this time.
0 commit comments