-
Notifications
You must be signed in to change notification settings - Fork 6
Document constructor naming conventions per semantic analysis #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c3384b7
958ec62
c0b5ddd
a6705a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -246,6 +246,79 @@ awmg/ | |||||||||||||||||||||||||||||||||||||||||
| - Add Godoc comments for all exported functions, types, and packages | ||||||||||||||||||||||||||||||||||||||||||
| - Mock external dependencies (Docker, network) in tests | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ### Constructor Naming Conventions | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| The codebase uses three distinct constructor patterns. Follow these conventions consistently: | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| #### 1. `New*(args) *Type` - Standard Constructors | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Use for simple object creation without error handling or complex initialization. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ```go | ||||||||||||||||||||||||||||||||||||||||||
| // Creates a new instance of the type directly | ||||||||||||||||||||||||||||||||||||||||||
| func NewConnection(ctx context.Context) *Connection { ... } | ||||||||||||||||||||||||||||||||||||||||||
| func NewRegistry() *Registry { ... } | ||||||||||||||||||||||||||||||||||||||||||
| func NewSession(sessionID, token string) *Session { ... } | ||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| **When to use:** | ||||||||||||||||||||||||||||||||||||||||||
| - Object creation is always successful (no errors to return) | ||||||||||||||||||||||||||||||||||||||||||
| - Direct instantiation of struct with provided parameters | ||||||||||||||||||||||||||||||||||||||||||
| - Most common pattern in the codebase (35+ usages) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| #### 2. `Create*(args) (Type, error)` - Factory Patterns | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Use for factory functions that perform registry lookups or complex configuration-based initialization. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ```go | ||||||||||||||||||||||||||||||||||||||||||
| // Looks up a guard type from registry and creates it | ||||||||||||||||||||||||||||||||||||||||||
| func CreateGuard(name string) (Guard, error) { ... } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // Complex initialization with potential failures | ||||||||||||||||||||||||||||||||||||||||||
| func CreateHTTPServerForMCP(cfg *Config) (*http.Server, error) { ... } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+269
to
+278
|
||||||||||||||||||||||||||||||||||||||||||
| #### 2. `Create*(args) (Type, error)` - Factory Patterns | |
| Use for factory functions that perform registry lookups or complex configuration-based initialization. | |
| ```go | |
| // Looks up a guard type from registry and creates it | |
| func CreateGuard(name string) (Guard, error) { ... } | |
| // Complex initialization with potential failures | |
| func CreateHTTPServerForMCP(cfg *Config) (*http.Server, error) { ... } | |
| #### 2. `Create*(args) (Type, error)` / `Create*(args) *Type` - Factory Patterns | |
| Use for factory functions that perform registry lookups or complex configuration-based initialization. Prefer returning `(Type, error)` when creation can fail; return only `*Type` when creation is guaranteed to succeed. | |
| ```go | |
| // Looks up a guard type from registry and creates it | |
| func CreateGuard(name string) (Guard, error) { ... } | |
| // HTTP server setup that cannot fail at creation time | |
| func CreateHTTPServerForMCP(addr string, unifiedServer *UnifiedServer, apiKey string) *http.Server { ... } |
Copilot
AI
Feb 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Init* examples/signatures are inconsistent with the actual logger APIs: InitFileLogger and InitJSONLLogger both take (logDir, fileName string) (not just dir string). Please update the example signatures here so contributors copy/paste the correct call pattern.
| func InitFileLogger(dir string) error { ... } | |
| // Initializes global JSON logger singleton | |
| func InitJSONLLogger(dir string) error { ... } | |
| func InitFileLogger(logDir, fileName string) error { ... } | |
| // Initializes global JSON logger singleton | |
| func InitJSONLLogger(logDir, fileName string) error { ... } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
New*examples/signature here don’t match the codebase:internal/mcp/connection.godefinesNewConnection(...) (*Connection, error)(andNewHTTPConnection(...) (*Connection, error)), so this section’s contract “no errors to return” and the examplefunc NewConnection(ctx context.Context) *Connectionare inaccurate. Please update the documentation to either (a) use examples that truly match theNew*(...) *Typepattern (e.g.,NewRegistry,NewSession) and state that constructors returning errors should beCreate*, or (b) adjust the stated pattern to reflect actual usage (but then the criteria bullets should change accordingly).This issue also appears on line 305 of the same file.