mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-29 16:06:36 +08:00
31 lines
583 B
Go
31 lines
583 B
Go
package controllers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/beego/beego/v2/server/web"
|
|
"net/http"
|
|
)
|
|
|
|
type BaseController struct {
|
|
web.Controller
|
|
}
|
|
|
|
func (c *BaseController) ServeJSON() {
|
|
c.Ctx.Output.Header("Content-Type", "application/json; charset=utf-8")
|
|
|
|
var err error
|
|
|
|
data := c.Data["json"]
|
|
|
|
encoder := json.NewEncoder(c.Ctx.Output.Context.ResponseWriter)
|
|
encoder.SetEscapeHTML(false)
|
|
|
|
encoder.SetIndent("", " ")
|
|
err = encoder.Encode(data)
|
|
|
|
if err != nil {
|
|
http.Error(c.Ctx.Output.Context.ResponseWriter, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
}
|