feat: initial commit
This commit is contained in:
38
reach/client/socketio/endpoint.go
Normal file
38
reach/client/socketio/endpoint.go
Normal file
@ -0,0 +1,38 @@
|
||||
package socketio
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
gosocketio "forge.cadoles.com/Pyxis/golang-socketio"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func EndpointFromHAddr(addr string) (string, error) {
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user