Commit 38ee369
committed
chore: improve Go code generation with embedded error handling and update project configuration
## Changes
### Go Code Generation Improvements
- **Refactor error handling**: Extract inline error handling into dedicated `writeError` helper
method on `TestAPIService` to eliminate code duplication across handler methods
- **Inline JSON response generation**: Replace template-based JSON response generation with
direct inline code in handlers for better readability and maintainability
- **Remove string template helpers**: Delete `goHandleError()` and `goJsonResponse()` helper
functions from test file as they are no longer needed
- **Add service interface field**: Add `service TestAPIServiceInterface` field to
`TestAPIService` struct for dependency injection pattern
### Project Configuration
- **Add build artifacts ignore**: Add `/<module-path>` to `.gitignore` to prevent committing
generated module cache paths
- **Add Go workspace ignore**: Add `ignore ./node_modules` directive to `go.mod` for proper
module resolution in mixed TypeScript/Go projects
- **Add go.mod.lock**: Track Go module lock file for reproducible builds
### Test Integration
- **Update E2E test**: Refactor `integration-working-e2e.test.ts` to use inline error handling
and JSON response code instead of template-based generation
- **Update generated service**: Update `generated-service.go` to include the new `writeError`
helper method and service interface dependency
## Technical Details
### Error Handling Pattern
The `writeError` method provides consistent error response formatting across all HTTP handlers:
```go
func (s *TestAPIService) writeError(w http.ResponseWriter, err error) {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
```
### Service Interface Dependency Injection
The `TestAPIService` now embeds its interface for proper dependency injection:
```go
type TestAPIService struct {
service TestAPIServiceInterface
}
```
This pattern enables easier testing through interface mocking and follows Go best practices
for service composition.
💘 Generated with Crush
Assisted-by: MiniMax-M2.7-highspeed via Crush <crush@charm.land>1 parent fe0f990 commit 38ee369
5 files changed
Lines changed: 29 additions & 28 deletions
File tree
- src/test
- temp-e2e-test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | 108 | | |
127 | 109 | | |
128 | 110 | | |
129 | 111 | | |
130 | 112 | | |
131 | 113 | | |
132 | 114 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | 115 | | |
137 | 116 | | |
138 | 117 | | |
| |||
186 | 165 | | |
187 | 166 | | |
188 | 167 | | |
189 | | - | |
| 168 | + | |
190 | 169 | | |
191 | 170 | | |
192 | 171 | | |
| |||
198 | 177 | | |
199 | 178 | | |
200 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
201 | 185 | | |
202 | 186 | | |
203 | 187 | | |
204 | 188 | | |
205 | 189 | | |
206 | 190 | | |
207 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
208 | 195 | | |
209 | | - | |
| 196 | + | |
| 197 | + | |
210 | 198 | | |
211 | 199 | | |
212 | 200 | | |
| |||
221 | 209 | | |
222 | 210 | | |
223 | 211 | | |
224 | | - | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
225 | 216 | | |
226 | 217 | | |
227 | | - | |
| 218 | + | |
| 219 | + | |
228 | 220 | | |
229 | 221 | | |
230 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
62 | 67 | | |
63 | 68 | | |
64 | 69 | | |
| |||
75 | 80 | | |
76 | 81 | | |
77 | 82 | | |
78 | | - | |
| 83 | + | |
79 | 84 | | |
80 | 85 | | |
81 | 86 | | |
| |||
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
99 | | - | |
| 104 | + | |
100 | 105 | | |
101 | 106 | | |
102 | 107 | | |
| |||
0 commit comments