Version Cursor rules
Track .cursor/rules/ in git so coding conventions are shared across the team. Everything else under .cursor/ stays ignored. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
38
.cursor/rules/go-url-construction.mdc
Normal file
38
.cursor/rules/go-url-construction.mdc
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
description: Go URL construction — never use fmt.Sprintf or concatenation for URLs
|
||||
globs: "**/*.go"
|
||||
alwaysApply: false
|
||||
---
|
||||
|
||||
# Go URL and query parameter construction
|
||||
|
||||
**Never** build URLs with `fmt.Sprintf`, string concatenation, or any string formatting.
|
||||
|
||||
Use `net/url` package or `pkg/baseurl.URLBuilder`.
|
||||
|
||||
```go
|
||||
// BAD
|
||||
endpoint := fmt.Sprintf("https://api.example.com/users/%s?active=%t", userID, active)
|
||||
endpoint := "https://api.example.com/orgs/" + orgID + "/members"
|
||||
raw := baseEndpoint + "?domain=" + domain + "&limit=100"
|
||||
|
||||
// GOOD — url.JoinPath + url.Values
|
||||
u, err := url.JoinPath("https://api.example.com", "users", userID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot build URL: %w", err)
|
||||
}
|
||||
|
||||
parsed, err := url.Parse(u)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot parse URL: %w", err)
|
||||
}
|
||||
|
||||
q := parsed.Query()
|
||||
q.Set("active", strconv.FormatBool(active))
|
||||
parsed.RawQuery = q.Encode()
|
||||
|
||||
// GOOD — URLBuilder from pkg/baseurl
|
||||
u, err := baseURL.URL("/users", userID).
|
||||
Query("active", strconv.FormatBool(active)).
|
||||
Build()
|
||||
```
|
||||
Reference in New Issue
Block a user