wsutil

package
v2.1.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2018 License: MIT Imports: 5 Imported by: 7

Documentation

Overview

Package wsutil provides websocket server utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowOrigins

func AllowOrigins(origins []string) (func(r *http.Request) bool, error)

AllowOriginsGlob returns a function, suitable for setting WebsocketServer.Upgrader.CheckOrigin, that returns true if: the origin is not set, is equal to the request host, or matches one of the allowed patterns. A pattern is in the form of a shell glob as described here: https://golang.org/pkg/path/filepath/#Match

Origins with Ports

To allow origins that have a port number, specify the port as part of the origin pattern, or use a wildcard to match the ports. See examples.

Allow a specific port, by specifying the expected port number:

check, err := AllowOrigins([]string{"*.somewhere.com:8080"})
if err != nil {
    log.Fatal(err)
}
wsServer.Upgrader.CheckOrigin = check

Allow individual ports, by specifying each port:

check, err := AllowOrigins([]string{
    "*.somewhere.com:8080",
    "*.somewhere.com:8905",
    "*.somewhere.com:8908",
})
if err != nil {
    log.Fatal(err)
}
wsServer.Upgrader.CheckOrigin = check

Allow any port, by specifying a wildcard. Be sure to include the colon ":" so that the pattern does not match a longer origin. Without the ":" this example would also match "x.somewhere.comics.net"

check, err := AllowOrigins([]string{"*.somewhere.com:*"})
if err != nil {
    log.Fatal(err)
}
wsServer.Upgrader.CheckOrigin = check

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL