Package list golang-github-nlopes-slack / upstream/0.1.0 websocket_utils.go
upstream/0.1.0

Tree @upstream/0.1.0 (Download .tar.gz)

websocket_utils.go @upstream/0.1.0raw · history · blame

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
}