作者 yangfu

公告上架下架

... ... @@ -18,8 +18,28 @@ type BaseController struct {
beego.Controller
}
func (this *BaseController) Options() {
this.AllowCross() //允许跨域
this.Data["json"] = map[string]interface{}{"status": 200, "message": "ok", "moreinfo": ""}
this.ServeJSON()
}
func (this *BaseController) AllowCross() {
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
//this.Ctx.WriteString("")
}
//Prepare 实现beego.ControllerInterface 的接口
func (this *BaseController) Prepare() {
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
if this.Ctx.Input.Method() == "OPTIONS" {
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
//this.Ctx.WriteString("")
return
}
p := this.Ctx.Input.GetData("RouterPattern")
fmt.Println("====>r:", p)
}
... ...
... ... @@ -13,7 +13,7 @@ const (
/*BulletinRelease */
type BulletinReleaseRequest struct {
Id int `json:"id"`
Type int `json:"type" valid:"Required"`
Type int `json:"type"`
Title string `json:"title" valid:"Required"`
Content string `json:"content" valid:"Required"`
AllowClose int `json:"allow_close"`
... ...