mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
See, $ gometalinter --vendor --deadline 10m --disable-all --enable=golint ./... ip.go:8:6⚠️ func SplitIpPort should be SplitIPPort (golint) url.go:14:6⚠️ func NewUrlQueryReader should be NewURLQueryReader (golint) url.go:9:6⚠️ type UrlQueryReader should be URLQueryReader (golint) url.go:37:6⚠️ func JoinUrlFragments should be JoinURLFragments (golint)
26 lines
438 B
Go
26 lines
438 B
Go
package util
|
|
|
|
import (
|
|
"net"
|
|
)
|
|
|
|
// SplitIPPort splits the ip string and port.
|
|
func SplitIPPort(ipStr string, portDefault string) (ip string, port string, err error) {
|
|
ipAddr := net.ParseIP(ipStr)
|
|
|
|
if ipAddr == nil {
|
|
// Port was included
|
|
ip, port, err = net.SplitHostPort(ipStr)
|
|
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
} else {
|
|
// No port was included
|
|
ip = ipAddr.String()
|
|
port = portDefault
|
|
}
|
|
|
|
return ip, port, nil
|
|
}
|