23 lines
445 B
Go
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)
|
|
}
|