Skip to content

Commit d31c719

Browse files
committed
updates but buggy try
1 parent c4c47a2 commit d31c719

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

main.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,23 @@ func post(w http.ResponseWriter, r *http.Request) {
4545
}
4646

4747
fmt.Println(response)
48+
type RespObject struct {
49+
Data []interface{}
50+
}
51+
respObject := RespObject{response}
52+
data, err := json.Marshal(respObject)
53+
if err != nil {
54+
fmt.Println(err)
55+
}
56+
fmt.Println("", data)
57+
58+
w.Header().Set("Content-Type", "application/json")
59+
w.WriteHeader(http.StatusOK)
60+
w.Write(data)
61+
// var res map[string]interface{}
62+
// json.Marshal(&response, &res)
4863

49-
w.WriteHeader(http.StatusCreated)
50-
w.Write([]byte(`{"message": "post called"}`))
64+
// w.Write([]byte(`{"message": "post called"}`))
5165
}
5266

5367
func get(w http.ResponseWriter, r *http.Request) {
@@ -96,6 +110,7 @@ func handleRequests() {
96110
api.HandleFunc("", notFound)
97111
api.HandleFunc("/user/{userID}/comment/{commentID}", withParams).Methods(http.MethodGet)
98112

113+
fmt.Println("Server started")
99114
log.Fatal(http.ListenAndServe(":8080", r))
100115
}
101116

0 commit comments

Comments
 (0)