[GO]Solve request origin not allowed by Upgrader.CheckOrigin websocket cross-domain

Using websocket under the gin framework, this error will be reported if it is a cross-domain request

request origin not allowed by Upgrader.CheckOrigin

 

The websocket library used is “github.com/gorilla/websocket”

Need to add the following code:

    upgrader = websocket.Upgrader{
        ReadBufferSize:   1024 ,
        WriteBufferSize: 1024 ,
         // Resolve cross-domain problems 
        CheckOrigin: func(r *http.Request) bool {
             return  true
        },
    }

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *