From b1bb14dfd4ee6cfcc6e94a97b0966528b8861f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Thu, 10 Mar 2022 11:26:07 +0100 Subject: [PATCH] ref: Change DSN ProjectID to be a string (#420) --- dsn.go | 13 +++++++------ dsn_test.go | 9 ++++----- transport.go | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dsn.go b/dsn.go index ca9f118b..5f5a13ce 100644 --- a/dsn.go +++ b/dsn.go @@ -45,7 +45,7 @@ type Dsn struct { host string port int path string - projectID int + projectID string } // NewDsn creates a Dsn by parsing rawURL. Most users will never call this @@ -104,9 +104,10 @@ func NewDsn(rawURL string) (*Dsn, error) { return nil, &DsnParseError{"empty project id"} } pathSegments := strings.Split(parsedURL.Path[1:], "/") - projectID, err := strconv.Atoi(pathSegments[len(pathSegments)-1]) - if err != nil { - return nil, &DsnParseError{"invalid project id"} + projectID := pathSegments[len(pathSegments)-1] + + if projectID == "" { + return nil, &DsnParseError{"empty project id"} } // Path @@ -140,7 +141,7 @@ func (dsn Dsn) String() string { if dsn.path != "" { url += dsn.path } - url += fmt.Sprintf("/%d", dsn.projectID) + url += fmt.Sprintf("/%s", dsn.projectID) return url } @@ -165,7 +166,7 @@ func (dsn Dsn) getAPIURL(s string) *url.URL { if dsn.path != "" { rawURL += dsn.path } - rawURL += fmt.Sprintf("/api/%d/%s/", dsn.projectID, s) + rawURL += fmt.Sprintf("/api/%s/%s/", dsn.projectID, s) parsedURL, _ := url.Parse(rawURL) return parsedURL } diff --git a/dsn_test.go b/dsn_test.go index 3c41ae43..91536cea 100644 --- a/dsn_test.go +++ b/dsn_test.go @@ -26,7 +26,7 @@ var dsnTests = map[string]DsnTest{ host: "domain", port: 8888, path: "/foo/bar", - projectID: 42, + projectID: "42", }, url: "https://domain:8888/foo/bar/api/42/store/", envURL: "https://domain:8888/foo/bar/api/42/envelope/", @@ -38,7 +38,7 @@ var dsnTests = map[string]DsnTest{ publicKey: "public", host: "domain", port: 443, - projectID: 42, + projectID: "42", }, url: "https://domain/api/42/store/", envURL: "https://domain/api/42/envelope/", @@ -50,7 +50,7 @@ var dsnTests = map[string]DsnTest{ publicKey: "public", host: "domain", port: 80, - projectID: 42, + projectID: "42", }, url: "http://domain/api/42/store/", envURL: "http://domain/api/42/envelope/", @@ -100,9 +100,8 @@ var invalidDsnTests = map[string]invalidDsnTest{ "NoProjectID2": {"https://public:secret@domain:8888", "empty project id"}, "BadURL": {"!@#$%^&*()", "invalid url"}, "BadScheme": {"ftp://public:secret@domain:8888/1", "invalid scheme"}, - "BadProjectID": {"https://public:secret@domain:8888/wbvdf7^W#$", "invalid project id"}, "BadPort": {"https://public:secret@domain:wat/42", "invalid port"}, - "TrailingSlash": {"https://public:secret@domain:8888/42/", "invalid project id"}, + "TrailingSlash": {"https://public:secret@domain:8888/42/", "empty project id"}, } //nolint: scopelint // false positive https://github.com/kyoh86/scopelint/issues/4 diff --git a/transport.go b/transport.go index c988c4cb..6a474179 100644 --- a/transport.go +++ b/transport.go @@ -304,7 +304,7 @@ func (t *HTTPTransport) SendEvent(event *Event) { eventType = fmt.Sprintf("%s event", event.Level) } Logger.Printf( - "Sending %s [%s] to %s project: %d", + "Sending %s [%s] to %s project: %s", eventType, event.EventID, t.dsn.host, @@ -511,7 +511,7 @@ func (t *HTTPSyncTransport) SendEvent(event *Event) { eventType = fmt.Sprintf("%s event", event.Level) } Logger.Printf( - "Sending %s [%s] to %s project: %d", + "Sending %s [%s] to %s project: %s", eventType, event.EventID, t.dsn.host,