overflow_server_app/commons/response.go
crusader 71b3163827 ing
2018-03-07 21:04:28 +09:00

23 lines
445 B
Go

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