1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/baetyl-baetyl-state

Клонировать/Скачать
responses.go 839
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
chensheng Отправлено 26.03.2020 13:30 52129db
package main
import (
"encoding/json"
routing "github.com/qiangxue/fasthttp-routing"
)
const (
jsonContentTypeHeader = "application/json"
)
// ErrorResponse ErrorResponse
type ErrorResponse struct {
ErrCode string `json:"errCode"`
Message string `json:"message"`
}
// NewErrorResponse NewErrorResponse
func NewErrorResponse(errCode, message string) ErrorResponse {
return ErrorResponse{
ErrCode: errCode,
Message: message,
}
}
func respondError(c *routing.Context, code int, errCode, msg string) {
resp := NewErrorResponse(errCode, msg)
b, _ := json.Marshal(&resp)
respond(c, code, b)
}
func respond(c *routing.Context, code int, obj []byte) {
c.RequestCtx.Response.SetStatusCode(code)
c.RequestCtx.Response.SetBody(obj)
if json.Valid(obj) {
c.RequestCtx.Response.Header.SetContentType(jsonContentTypeHeader)
}
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/baetyl-baetyl-state.git
git@api.gitlife.ru:oschina-mirror/baetyl-baetyl-state.git
oschina-mirror
baetyl-baetyl-state
baetyl-baetyl-state
master