mirror of
https://github.com/wweir/sower.git
synced 2024-04-21 12:42:15 +00:00
20 lines
355 B
Go
20 lines
355 B
Go
package util
|
|
|
|
import (
|
|
"net"
|
|
"strconv"
|
|
)
|
|
|
|
func ParseHostPort(addr string, defaultPort uint16) (string, uint16) {
|
|
h, p, err := net.SplitHostPort(addr)
|
|
if err != nil {
|
|
if defaultPort == 0 {
|
|
panic("parse port fail with no default, addr: " + addr)
|
|
}
|
|
return addr, defaultPort
|
|
}
|
|
|
|
pNum, _ := strconv.ParseUint(p, 10, 16)
|
|
return h, uint16(pNum)
|
|
}
|