diff --git a/address.go b/address.go new file mode 100644 index 0000000..dadf5d3 --- /dev/null +++ b/address.go @@ -0,0 +1,34 @@ +package rabbit + +import ( + "errors" + "fmt" + "net/url" +) + +type Address struct { + Username string + Password string + Host string + Port uint16 + Vhost string +} + +func (a *Address) makeAddr() (string, error) { + if a.Host == "" { + return "", errors.New("no host provided") + } + + if a.Vhost == "" { + return "", errors.New("no vhost provided") + } + + //"amqp://username:password@host:port/vhost" + return fmt.Sprintf("amqp://%v:%v@%v:%v/%v", + url.QueryEscape(a.Username), + url.QueryEscape(a.Password), + a.Host, + a.Port, + url.PathEscape(a.Vhost), + ), nil +}