Beispiel #1
0
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)
	}
}
Beispiel #2
0
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)
	}
}
Beispiel #3
0
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)
	}
}