mt-rabbit/address.go

35 lines
559 B
Go
Raw Normal View History

2026-04-03 11:21:24 +03:00
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
}