Skip to content

Commit

Permalink
Merge pull request #253 from michaelklishin/fix-delete-binding-panic
Browse files Browse the repository at this point in the history
Avoid out of range panic when destination type is not set
  • Loading branch information
michaelklishin committed Feb 23, 2023
2 parents 462922a + c3394f4 commit 5aa2074
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions bindings.go
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

0 comments on commit 5aa2074

Please sign in to comment.