18 lines
353 B
Go
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()})
|
|
}
|