Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
)

type UserData struct {
Name string
FirstName string
LastName string
Email string
}

func main() {
Expand All @@ -22,7 +24,7 @@ func main() {
mux.HandleFunc("/hello/", handleHelloParameterized)
mux.HandleFunc("/responses/{user}/hello/", handleUserResponsesHello)
mux.HandleFunc("/user/hello", handleHelloHeader)
mux.HandleFunc("/json", handleJSON)
mux.HandleFunc("POST /json", handleJSON)

fmt.Println("Listening on port 4000")

Expand Down Expand Up @@ -119,12 +121,12 @@ func handleJSON(w http.ResponseWriter, r *http.Request) {
return
}

if reqData.Name == "" {
if reqData.FirstName == "" {
http.Error(w, "invalid request body!", http.StatusBadRequest)
return
}

handleHello(w, reqData.Name)
handleHello(w, reqData.FirstName)

}

Expand Down
4 changes: 2 additions & 2 deletions cmd/server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestHandleHelloNoHeader(t *testing.T) {

func TestHandleJSON(t *testing.T) {
testRequest := UserData{
Name: "human",
FirstName: "human",
}

marshalledRequestBody, err := json.Marshal(testRequest)
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestHandleJSONEmptyBody(t *testing.T) {

func TestHandleJSONEmptyNameFeild(t *testing.T) {
testRequest := UserData{
Name: "",
FirstName: "",
}

marshalledRequestBody, err := json.Marshal(testRequest)
Expand Down
Loading