2024-07-30 14:28:39 +02:00
|
|
|
package socketio
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
gosocketio "forge.cadoles.com/Pyxis/golang-socketio"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2024-08-05 18:10:19 +02:00
|
|
|
func EndpointFromAddr(addr string) (string, error) {
|
2024-07-30 14:28:39 +02:00
|
|
|
host, rawPort, err := net.SplitHostPort(addr)
|
|
|
|
if err != nil {
|
|
|
|
var addrErr *net.AddrError
|
|
|
|
if !errors.As(err, &addrErr) || !strings.Contains(addrErr.Error(), "missing port in address") {
|
|
|
|
return "", errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
host = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
port := int64(80)
|
|
|
|
if rawPort != "" {
|
|
|
|
port, err = strconv.ParseInt(rawPort, 10, 32)
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.WithStack(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
endpoint := Endpoint(host, int(port), false)
|
|
|
|
|
|
|
|
return endpoint, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Endpoint(host string, port int, secure bool) string {
|
|
|
|
return gosocketio.GetUrl(host, port, false)
|
|
|
|
}
|