Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid out of range panic when destination type is not set #253

Merged
merged 1 commit into from
Feb 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (c *Client) DeclareBinding(vhost string, info BindingInfo) (res *http.Respo
return nil, err
}

req, err := newRequestWithBody(c, "POST", c.newBindingPath(vhost, info), body)
req, err := newRequestWithBody(c, "POST", c.bindingPath(vhost, info), body)

if err != nil {
return nil, err
Expand All @@ -195,7 +195,7 @@ func (c *Client) DeclareBinding(vhost string, info BindingInfo) (res *http.Respo
return res, nil
}

func (c *Client) newBindingPath(vhost string, info BindingInfo) string {
func (c *Client) bindingPath(vhost string, info BindingInfo) string {
if info.DestinationType == "queue" {
// /api/bindings/{vhost}/e/{exchange}/q/{queue}
return "bindings/" + url.PathEscape(vhost) +
Expand All @@ -214,9 +214,8 @@ func (c *Client) newBindingPath(vhost string, info BindingInfo) string {

// DeleteBinding deletes an individual binding
func (c *Client) DeleteBinding(vhost string, info BindingInfo) (res *http.Response, err error) {
req, err := newRequestWithBody(c, "DELETE", "bindings/"+url.PathEscape(vhost)+
"/e/"+url.PathEscape(info.Source)+"/"+url.PathEscape(string(info.DestinationType[0]))+
"/"+url.PathEscape(info.Destination)+"/"+url.PathEscape(info.PropertiesKey), nil)
req, err := newRequestWithBody(c, "DELETE", c.bindingPath(vhost, info) +
"/"+url.PathEscape(info.PropertiesKey), nil)
if err != nil {
return nil, err
}
Expand Down