You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,21 +83,28 @@ Providers implement `ErrorConverter` using `errors.As` with SDK typed errors (no
83
83
### Key Patterns
84
84
85
85
-**Configuration**: Functional options with validation
86
-
-**Constants**: Extract ALL magic strings to named constants (including response format types like `json_object`)
86
+
-**Constants**: Extract ALL magic strings to named constants (including response format types like `json_object`). Constants belong in production code files, not test files
87
87
-**Streaming**: Break monolithic handlers into focused methods (see `anthropic/anthropic.go`)
88
88
-**Streaming Safety**: Always use `select` with `ctx.Done()` when sending to channels in goroutines to prevent blocking forever if consumer abandons
89
89
-**ID Generation**: Use `crypto/rand`, not package-level mutable state
90
90
-**Error Conversion**: Use `errors.As` with SDK typed errors; avoid string matching when possible
91
91
-**Input Validation**: Validate required fields (Model non-empty, Messages has entries) before API calls
92
92
-**Unknown Values**: Never silently convert unknown enum values (e.g., unknown role → user); error or log warning instead
93
93
-**Struct Field Order**: Order struct fields A-Z (don't optimize for padding)
94
+
-**Slice Cloning**: Prefer `slices.Clone` over manual `make` + `copy`
95
+
-**Slice Capacity**: Use `make([]T, 0, len(source))` when building slices from known-size sources
96
+
-**ContentString()**: Use `msg.ContentString()` instead of `msg.Content.(string)` type assertions
97
+
-**Switch Completeness**: Switch statements should have a `default` case (error or explicit fallback)
98
+
-**Variable Naming**: Don't shadow imported package names (e.g., use `imgURL` not `url` when `net/url` is imported)
99
+
-**Error Messages**: Don't double-print provider name when the base error already includes it
94
100
95
101
### OpenAI-Compatible Providers
96
102
97
103
For providers that expose OpenAI-compatible APIs but don't have their own Go SDK (Llamafile, vLLM, LM Studio, etc.):
98
104
- Use the compatible provider in `providers/openai/compatible.go`
0 commit comments