address maker
This commit is contained in:
parent
e58b052251
commit
44d99a4ba5
1 changed files with 34 additions and 0 deletions
34
address.go
Normal file
34
address.go
Normal file
|
|
@ -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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue