Skip to content

Commit

Permalink
Merge pull request #55 from seipan/feat/example-people-all-api
Browse files Browse the repository at this point in the history
exampleに```/v1/people/all```を追加する。
  • Loading branch information
takanakahiko authored Nov 15, 2023
2 parents 7ed91be + b535ae2 commit 63647c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Binary file added example/atgen
Binary file not shown.
8 changes: 8 additions & 0 deletions example/handlers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func GetPeople(w http.ResponseWriter, r *http.Request) {
})
}

func GetPeopleArray(w http.ResponseWriter, r *http.Request) {
person1 := Person{ID: "1", Firstname: "John", Lastname: "Doe"}
person2 := Person{ID: "2", Firstname: "Jane", Lastname: "Doe"}
people := []Person{person1, person2}
json.NewEncoder(w).Encode(people)
}

// GetPerson displays a single data
func GetPerson(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
Expand Down Expand Up @@ -88,6 +95,7 @@ func GetRouter() *mux.Router {
people = append(people, Person{ID: "1", Firstname: "John", Lastname: "Doe", Address: &Address{City: "City X", State: "State X"}})
people = append(people, Person{ID: "2", Firstname: "Koko", Lastname: "Doe", Address: &Address{City: "City Z", State: "State Y"}})
router.HandleFunc("/v1/people", GetPeople).Methods("GET")
router.HandleFunc("/v1/people/all", GetPeopleArray).Methods("GET")
router.HandleFunc("/v1/people/{id}", GetPerson).Methods("GET")
router.HandleFunc("/v1/people/{id}", CreatePerson).Methods("POST")
router.HandleFunc("/v1/form/people/{id}", CreatePersonFromForm).Methods("POST")
Expand Down

0 comments on commit 63647c1

Please sign in to comment.