mirror of
https://github.com/fatedier/frp.git
synced 2026-03-22 09:49:16 +08:00
use net.JoinHostPort instead of fmt.Sprintf (#2791)
This commit is contained in:
@@ -34,17 +34,6 @@ func OkResponse() *http.Response {
|
||||
return res
|
||||
}
|
||||
|
||||
// TODO: use "CanonicalHost" func to replace all "GetHostFromAddr" func.
|
||||
func GetHostFromAddr(addr string) (host string) {
|
||||
strs := strings.Split(addr, ":")
|
||||
if len(strs) > 1 {
|
||||
host = strs[0]
|
||||
} else {
|
||||
host = addr
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// canonicalHost strips port from host if present and returns the canonicalized
|
||||
// host name.
|
||||
func CanonicalHost(host string) (string, error) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -52,7 +53,7 @@ func CanonicalAddr(host string, port int) (addr string) {
|
||||
if port == 80 || port == 443 {
|
||||
addr = host
|
||||
} else {
|
||||
addr = fmt.Sprintf("%s:%d", host, port)
|
||||
addr = net.JoinHostPort(host, strconv.Itoa(port))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user