overflow_server_app/commons/error_response.go
crusader 46cfc967a9 ing
2018-03-06 12:23:57 +09:00

23 lines
457 B
Go

package commons
import (
"encoding/json"
"github.com/valyala/fasthttp"
)
func SendRESTResponse(ctx *fasthttp.RequestCtx, response interface{}) {
ctx.SetContentType("application/javascript")
jRes, _ := json.Marshal(response)
ctx.SetBody(jRes)
}
func SendRESTError(ctx *fasthttp.RequestCtx, statusCode int, err error) {
ctx.SetContentType("application/javascript")
ctx.SetStatusCode(statusCode)
jRes, _ := json.Marshal(err)
ctx.SetBody(jRes)
}