From c3394f4a840879aa876d6bbb708d91ac22de2fd3 Mon Sep 17 00:00:00 2001 From: Chunyi Lyu Date: Thu, 23 Feb 2023 12:13:06 +0000 Subject: [PATCH] Avoid out of range panic when destType is not set - info.DestinationType[0] panics if it's an empty string - rename newBindingPath helper to bindingPath --- bindings.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bindings.go b/bindings.go index ecf997e..614424e 100644 --- a/bindings.go +++ b/bindings.go @@ -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 @@ -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) + @@ -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 }