package commons import ( "encoding/json" "github.com/valyala/fasthttp" ) func SendRESTResponse(ctx *fasthttp.RequestCtx, response interface{}) { ctx.SetContentType("application/json") var body []byte switch response.(type) { default: body, _ = json.Marshal(response) case string: body = []byte(response.(string)) } ctx.SetBody(body) } func SendRESTError(ctx *fasthttp.RequestCtx, statusCode int, err error) { ctx.SetContentType("application/json") ctx.SetStatusCode(statusCode) jRes, _ := json.Marshal(err) ctx.SetBody(jRes) }