123456789101112131415161718192021222324252627282930313233 |
- package utils
- import (
- "net/url"
- "strconv"
- "strings"
- )
- // HostAndIpToBits parses an address parsing out the host and port
- // Example input - http://abc.com:1234 returns { true, http, abc.com, 1234 }
- func HostAndIpToBits(address string) (bool, string, string, int) {
- url, err := url.Parse(address)
- if err != nil {
- return false, "", "", 0
- }
- bits := strings.Split(url.Host, ":")
- if len(bits) != 2 {
- return false, "", "", 0
- }
- port, err := strconv.Atoi(bits[1])
- if err != nil {
- return false, "", "", 0
- }
- return true, url.Scheme, bits[0], port
- }
|