在gin框架下使用websocket , 如果是跨域请求的时候会报这个错误
request origin not allowed by Upgrader.CheckOrigin
使用的websocket库是 "github.com/gorilla/websocket"
需要增加以下代码:
upgrader = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, // 解决跨域问题 CheckOrigin: func(r *http.Request) bool { return true }, }
[GO]解决request origin not allowed by Upgrader.CheckOrigin websocket跨域