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
2017-09-23 11:26:52 -07:00

18 lines
353 B
Go

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()})
}