func ParseURI(uri string) (URI, error) {
	builder := defaultURI
	if strings.Contains(uri, " ") == true {
		return builder, errURIWhitespace
	}
	u, err := url.Parse(uri)
	if err != nil {
		return builder, err
	}
	defaultPort, okScheme := schemePorts[u.Scheme]
	if okScheme {
		builder.Scheme = u.Scheme
	} else {
		return builder, errURIScheme
	}
	host := u.Hostname()
	port := u.Port()
	if host != "" {
		builder.Host = host
	}
	if port != "" {
		port32, err := strconv.ParseInt(port, 10, 32)
		if err != nil {
			return builder, err
		}
		builder.Port = int(port32)
	} else {
		builder.Port = defaultPort
	}
	if u.User != nil {
		builder.Username = u.User.Username()
		if password, ok := u.User.Password(); ok {
			builder.Password = password
		}
	}
	if u.Path != "" {
		if strings.HasPrefix(u.Path, "/") {
			if u.Host == "" && strings.HasPrefix(u.Path, "///") {
				if len(u.Path) > 3 {
					builder.Vhost = u.Path[3:]
				}
			} else if len(u.Path) > 1 {
				builder.Vhost = u.Path[1:]
			}
		} else {
			builder.Vhost = u.Path
		}
	}
	return builder, nil
}
ParseURI attempts to parse the given AMQP URI according to the spec.
See http://www.rabbitmq.com/uri-spec.html.

Default values for the fields are:

Scheme: amqp
Host: localhost
Port: 5672
Username: guest
Password: guest
Vhost: /
package amqp
import (
	"errors"
	"net"
	"net/url"
	"strconv"
	"strings"
)
var errURIScheme = errors.New("AMQP scheme must be either 'amqp://' or 'amqps://'")
var errURIWhitespace = errors.New("URI must not contain whitespace")
var schemePorts = map[string]int{
	"amqp":  5672,
	"amqps": 5671,
}
var defaultURI = URI{
	Scheme:   "amqp",
	Host:     "localhost",
	Port:     5672,
	Username: "guest",
	Password: "guest",
	Vhost:    "/",
}
type URI struct {
	Scheme   string
	Host     string
	Port     int
	Username string
	Password string
	Vhost    string
}