Package list golang-github-nlopes-slack / lintian-fixes/main websocket_utils.go
lintian-fixes/main

Tree @lintian-fixes/main (Download .tar.gz)

websocket_utils.go @lintian-fixes/main

334c7e2
 
 
 
 
 
 
 
 
32464d1
334c7e2
 
 
 
 
 
 
 
 
 
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
}