Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created September 11, 2022 06:10
Show Gist options
  • Save percybolmer/8e5622f896fce9047196d92348aa5fb8 to your computer and use it in GitHub Desktop.
Save percybolmer/8e5622f896fce9047196d92348aa5fb8 to your computer and use it in GitHub Desktop.
var (
/**
websocketUpgrader is used to upgrade incomming HTTP requests into a persitent websocket connection
*/
websocketUpgrader = websocket.Upgrader{
// Apply the Origin Checker
CheckOrigin: checkOrigin,
ReadBufferSize: 1024,
WriteBufferSize: 1024,
}
)
var (
ErrEventNotSupported = errors.New("this event type is not supported")
)
// checkOrigin will check origin and return true if its allowed
func checkOrigin(r *http.Request) bool {
// Grab the request origin
origin := r.Header.Get("Origin")
switch origin {
case "http://localhost:8080":
return true
default:
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment