package encoders import ( "encoding/json" "net/http" pb "go.unistack.org/unistack-org/pkgdash/proto" "github.com/pkg/errors" ) type JSON struct{} func (*JSON) Success(rw http.ResponseWriter, response interface{}) error { rw.Header().Set("Content-Type", "application/json; charset=utf-8") rw.WriteHeader(http.StatusOK) return errors.WithStack(json.NewEncoder(rw).Encode(response)) } func (*JSON) Error(rw http.ResponseWriter, err *pb.Error, status int) error { rw.Header().Set("Content-Type", "application/problem+json; charset=utf-8") rw.WriteHeader(status) return errors.WithStack(json.NewEncoder(rw).Encode(&pb.ErrorRsp{Error: err})) }