This repository has been archived on 2022-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
tacitus/http/util.go

18 lines
353 B
Go
Raw Normal View History

2017-09-09 10:14:50 -07:00
package http
import (
"encoding/json"
"net/http"
)
func encodeJson(w http.ResponseWriter, data interface{}) {
if buf, err := json.Marshal(data); err == nil {
w.Header().Add("Content-Type", "application/json")
w.Write(buf)
}
}
func errorResp(w http.ResponseWriter, err error) {
json.NewEncoder(w).Encode(&errorResponse{Error: err.Error()})
}