Пример #1
0
func GetProfileByKey(ctx context.Context, w http.ResponseWriter, r *http.Request) (int, error) {
	if r.Method != "GET" {
		return http.StatusMethodNotAllowed, nil
	}

	key, err := datastore.DecodeKey(mux.Vars(r)["key"])

	if err != nil {
		return http.StatusBadRequest, err
	}

	var profile model.Profile
	if err := datastore.Get(ctx, key, &profile); err != nil {
		return http.StatusInternalServerError, err
	}
	json.NewEncoder(w).Encode(profile.Key(key))
	return http.StatusOK, nil
}