You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
426 B
Go
21 lines
426 B
Go
8 years ago
|
package slack
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
"net/url"
|
||
|
)
|
||
|
|
||
|
var portMapping = map[string]string{"ws": "80", "wss": "443"}
|
||
|
|
||
|
func websocketizeURLPort(orig string) (string, error) {
|
||
|
urlObj, err := url.ParseRequestURI(orig)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
_, _, err = net.SplitHostPort(urlObj.Host)
|
||
|
if err != nil {
|
||
|
return urlObj.Scheme + "://" + urlObj.Host + ":" + portMapping[urlObj.Scheme] + urlObj.Path, nil
|
||
|
}
|
||
|
return orig, nil
|
||
|
}
|