Skip to content

Commit 2fa4d83

Browse files
authored
Merge pull request #25 from chenzhihao/fix-endpoint-url
fix the endpoint
2 parents 921296c + 3713b1d commit 2fa4d83

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"io/ioutil"
1111
"net/http"
12+
"strings"
1213
"time"
1314
)
1415

@@ -124,7 +125,12 @@ func (c *Client) newRequest(method, endpoint string, in interface{}) (*http.Requ
124125
bodyreader = newbodyreader
125126
}
126127

127-
req, err := http.NewRequest(method, c.Endpoint+endpoint+"/", bodyreader)
128+
finalEndpoint := c.Endpoint+endpoint
129+
if !strings.HasSuffix(endpoint, "/") {
130+
finalEndpoint = finalEndpoint + "/"
131+
}
132+
133+
req, err := http.NewRequest(method, finalEndpoint, bodyreader)
128134
if err != nil {
129135
return nil, err
130136
}

client_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,19 @@ func TestClientKnownGoodEndpoint(t *testing.T) {
6262
t.Errorf("Endpoint is not https://sentry.io/api/0 got %s", bclient.Endpoint)
6363
}
6464
}
65+
66+
func TestNewRequestWillNotAddExtraTrailingSlashToEndpoint(t *testing.T) {
67+
endpoint := "some-endpoint/"
68+
bclient, berr := NewClient("testauthclient", nil, nil)
69+
if berr != nil {
70+
t.Error(berr)
71+
}
72+
req, err := bclient.newRequest("get", endpoint, nil)
73+
if req == nil || err != nil {
74+
t.Errorf("can't generate request: %v", err)
75+
}
76+
77+
if req.URL.String() != "https://sentry.io/api/0/some-endpoint/" {
78+
t.Errorf("Endpoint is not https://sentry.io/api/0/some-endpoint/ got %s", req.URL.String())
79+
}
80+
}

project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (c *Client) GetProjects() ([]Project, *Link, error) {
8181
// GetOrgProjects fetchs all projects belonging to a organization
8282
func (c *Client) GetOrgProjects(o Organization) ([]Project, *Link, error) {
8383
var proj []Project
84-
link, err := c.doWithPagination("GET", fmt.Sprintf("organizations/%s/projects/", *o.Slug), &proj, nil)
84+
link, err := c.doWithPagination("GET", fmt.Sprintf("organizations/%s/projects", *o.Slug), &proj, nil)
8585
return proj, link, err
8686
}
8787

0 commit comments

Comments
 (0)