Пример #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)
	}
}
Пример #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)
	}
}
Пример #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)
	}
}