all repos — go-lift @ 092e7440440b8459d82fb90c05c005f9f38e3c51

Lightweight workout tracker prototype..

src/api/utils.go (view raw)

 1package api
 2
 3import (
 4	"encoding/json"
 5	"net/http"
 6	"strings"
 7)
 8
 9func jsonResponse(w http.ResponseWriter, status int, data interface{}) {
10	w.Header().Set("Content-Type", "application/json")
11	w.WriteHeader(status)
12	json.NewEncoder(w).Encode(data)
13}
14
15func jsonError(w http.ResponseWriter, status int, messages ...string) {
16	jsonResponse(w, status, map[string]string{"error": strings.Join(messages, " ")})
17}