func Index(w http.ResponseWriter, r *http.Request) { defer response.InternalError(w) states, err := All() if err != nil { response.Error(http.StatusInternalServerError, err.Error(), w) } else { response.Ok(states, w) } }
func FindId(w http.ResponseWriter, r *http.Request) { defer response.InternalError(w) params := mux.Vars(r) id := params["id"] country, err := FindById(id) if err != nil { response.Error(http.StatusNotFound, err.Error(), w) } else { response.Ok(country, w) } }
func IndexWithLink(w http.ResponseWriter, r *http.Request) { defer response.InternalError(w) states, err := All() if err != nil { response.Error(http.StatusInternalServerError, err.Error(), w) } else { state := states[0] responseState := ResponseState{ State: state, Links: []HyperLink{ HyperLink{ Relation: "country", URL: "/ams/country/v1/" + state.CountryId.Hex(), Method: "GET", }, }, } response.Ok(responseState, w) } }