Files
jx-callback/controllers/print_controller.go
suyl 7267473617 aa
2021-06-15 14:47:51 +08:00

46 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package controllers
import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
beego "github.com/astaxie/beego/server/web"
"github.com/gorilla/websocket"
"net/http"
)
type PrintController struct {
beego.Controller
}
type CallBackPrint struct {
Data string `json:"data"`
Code string `json:"code"`
}
// 配置升级程序(升级为websocket)
var upgrader2 = websocket.Upgrader{}
func (c *PrintController) Msg() {
// 解决跨域问题(微信小程序)
upgrader2.CheckOrigin = func(r *http.Request) bool {
return true
}
//升级将HTTP服务器连接升级到WebSocket协议。
//responseHeader包含在对客户端升级的响应中
//请求。使用responseHeader指定Cookie设置Cookie
//应用程序协商的子目录Sec WebSocket协议
//如果升级失败则升级将向客户端答复一个HTTP错误
_, err := upgrader2.Upgrade(c.Ctx.ResponseWriter, c.Ctx.Request, nil)
//if c.Ctx.Input.Method() == http.MethodPost {
callBackPrint := &CallBackPrint{}
globals.SugarLogger.Debugf("print callback callbackResponse:%s", utils.Format4Output(c.Ctx.Request, true))
if err != nil {
callBackPrint.Data = err.Error()
}
c.Data["json"] = callBackPrint
c.ServeJSON()
//} else {
// c.Abort("404")
//}
}