// @Title State // @Description 获取当前网关状态 // @Success 200 {string} state // @Failure 401 :gate is out of server // @router /state [get] func (this *GateController) State() { signal := rpc.RPC_SIGNAL_TEST reply := new(int) if err := rpc.Test(signal, reply); err == nil { if (*reply) == rpc.RPC_SIGNAL_TEST_REPLY { this.Data["json"] = map[string]interface{}{ "code": 0, "data": "ok", } } else { this.ResponseErrorJSON(401, "not ok") } } else { this.ResponseErrorJSON(500, err.Error()) } this.ServeJson() }
func main() { if beego.RunMode == "dev" { beego.DirectoryIndex = true beego.StaticDir["/document"] = "swagger" } beego.InsertFilter("*", beego.BeforeRouter, func(ctx *context.Context) { ctx.Output.Header("Access-Control-Allow-Origin", "*") }) var testReply int if err := rpc.Test(rpc.RPC_SIGNAL_TEST, &testReply); err != nil { log.Println(err.Error()) } else { if testReply != rpc.RPC_SIGNAL_TEST_REPLY { log.Println("RPC service has error.") } } beego.Run() }