Skip to content

Commit 5c25cc5

Browse files
committed
feat(makefile): enhance formatting and vetting for all Go modules
- Updated the `fmt`, `vet`, and `tidy` targets in the Makefile to format, vet, and tidy all Go modules individually, improving modularity and clarity in the build process. - Enhanced output messages to reflect the processing of multiple modules, providing better feedback during execution. - Cleaned up unnecessary blank lines and improved code readability in several example files across the project. This update improves the maintainability and usability of the Makefile for developers working with multiple Go modules.
1 parent 3907b6e commit 5c25cc5

67 files changed

Lines changed: 1323 additions & 493 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,27 @@ install:
127127
# ==============================================================================
128128

129129
.PHONY: test
130-
## test: Run all tests with race detector
130+
## test: Run all tests with race detector in all modules
131131
test:
132-
@echo "$(COLOR_GREEN)Running tests...$(COLOR_RESET)"
133-
@$(GOTEST) $(TEST_FLAGS) $(TEST_DIRS)
134-
@echo "$(COLOR_GREEN)✓ All tests passed$(COLOR_RESET)"
132+
@echo "$(COLOR_GREEN)Running tests in all modules...$(COLOR_RESET)"
133+
@COUNT=0; FAILED=0; \
134+
ROOT_DIR=$$(pwd); \
135+
for modfile in $$(find . -name "go.mod" -type f | grep -v "/vendor/" | sort); do \
136+
dir=$$(dirname $$modfile); \
137+
echo " Testing $$dir..."; \
138+
if cd "$$ROOT_DIR/$$dir" && $(GOTEST) $(TEST_FLAGS) ./...; then \
139+
COUNT=$$((COUNT + 1)); \
140+
else \
141+
FAILED=$$((FAILED + 1)); \
142+
fi; \
143+
done; \
144+
cd "$$ROOT_DIR"; \
145+
if [ $$FAILED -eq 0 ]; then \
146+
echo "$(COLOR_GREEN)✓ All tests passed in $$COUNT modules$(COLOR_RESET)"; \
147+
else \
148+
echo "$(COLOR_RED)✗ Tests failed in $$FAILED module(s), passed in $$COUNT module(s)$(COLOR_RESET)"; \
149+
exit 1; \
150+
fi
135151

136152
.PHONY: test-short
137153
## test-short: Run tests with -short flag
@@ -217,16 +233,31 @@ bench-compare:
217233
# ==============================================================================
218234

219235
.PHONY: lint
220-
## lint: Run golangci-lint
236+
## lint: Run golangci-lint on all modules
221237
lint:
222-
@echo "$(COLOR_GREEN)Running linter...$(COLOR_RESET)"
223-
@if command -v $(GOLANGCI_LINT) >/dev/null 2>&1; then \
224-
$(GOLANGCI_LINT) run $(LINT_DIRS) --timeout=5m; \
225-
echo "$(COLOR_GREEN)✓ Linting passed$(COLOR_RESET)"; \
226-
else \
238+
@echo "$(COLOR_GREEN)Running linter on all modules...$(COLOR_RESET)"
239+
@if ! command -v $(GOLANGCI_LINT) >/dev/null 2>&1; then \
227240
echo "$(COLOR_RED)Error: golangci-lint not found. Run 'make install-tools' to install$(COLOR_RESET)"; \
228241
exit 1; \
229242
fi
243+
@COUNT=0; FAILED=0; \
244+
ROOT_DIR=$$(pwd); \
245+
for modfile in $$(find . -name "go.mod" -type f | grep -v "/vendor/" | sort); do \
246+
dir=$$(dirname $$modfile); \
247+
echo " Linting $$dir..."; \
248+
if cd "$$ROOT_DIR/$$dir" && $(GOLANGCI_LINT) run ./... --timeout=5m; then \
249+
COUNT=$$((COUNT + 1)); \
250+
else \
251+
FAILED=$$((FAILED + 1)); \
252+
fi; \
253+
done; \
254+
cd "$$ROOT_DIR"; \
255+
if [ $$FAILED -eq 0 ]; then \
256+
echo "$(COLOR_GREEN)✓ Linting passed for $$COUNT modules$(COLOR_RESET)"; \
257+
else \
258+
echo "$(COLOR_RED)✗ Linting failed in $$FAILED module(s), passed in $$COUNT module(s)$(COLOR_RESET)"; \
259+
exit 1; \
260+
fi
230261

231262
.PHONY: lint-fix
232263
## lint-fix: Run golangci-lint with auto-fix
@@ -235,11 +266,19 @@ lint-fix:
235266
@$(GOLANGCI_LINT) run $(LINT_DIRS) --fix --timeout=5m
236267

237268
.PHONY: fmt
238-
## fmt: Format Go code
269+
## fmt: Format Go code in all modules
239270
fmt:
240-
@echo "$(COLOR_GREEN)Formatting code...$(COLOR_RESET)"
241-
@$(GOFMT) $(TEST_DIRS)
242-
@echo "$(COLOR_GREEN)✓ Code formatted$(COLOR_RESET)"
271+
@echo "$(COLOR_GREEN)Formatting code in all modules...$(COLOR_RESET)"
272+
@COUNT=0; \
273+
ROOT_DIR=$$(pwd); \
274+
for modfile in $$(find . -name "go.mod" -type f | grep -v "/vendor/" | sort); do \
275+
dir=$$(dirname $$modfile); \
276+
echo " Formatting $$dir..."; \
277+
cd "$$ROOT_DIR/$$dir" && $(GOFMT) ./...; \
278+
COUNT=$$((COUNT + 1)); \
279+
done; \
280+
cd "$$ROOT_DIR"; \
281+
echo "$(COLOR_GREEN)✓ Formatted $$COUNT modules$(COLOR_RESET)"
243282

244283
.PHONY: fmt-check
245284
## fmt-check: Check if code is formatted
@@ -249,18 +288,34 @@ fmt-check:
249288
(echo "$(COLOR_RED)Code is not formatted. Run 'make fmt'$(COLOR_RESET)" && exit 1)
250289

251290
.PHONY: vet
252-
## vet: Run go vet
291+
## vet: Run go vet on all modules
253292
vet:
254-
@echo "$(COLOR_GREEN)Running go vet...$(COLOR_RESET)"
255-
@$(GOVET) $(TEST_DIRS)
256-
@echo "$(COLOR_GREEN)✓ Vet passed$(COLOR_RESET)"
293+
@echo "$(COLOR_GREEN)Running go vet on all modules...$(COLOR_RESET)"
294+
@COUNT=0; \
295+
ROOT_DIR=$$(pwd); \
296+
for modfile in $$(find . -name "go.mod" -type f | grep -v "/vendor/" | sort); do \
297+
dir=$$(dirname $$modfile); \
298+
echo " Vetting $$dir..."; \
299+
cd "$$ROOT_DIR/$$dir" && $(GOVET) ./...; \
300+
COUNT=$$((COUNT + 1)); \
301+
done; \
302+
cd "$$ROOT_DIR"; \
303+
echo "$(COLOR_GREEN)✓ Vet passed for $$COUNT modules$(COLOR_RESET)"
257304

258305
.PHONY: tidy
259-
## tidy: Tidy go modules
306+
## tidy: Tidy all go modules
260307
tidy:
261-
@echo "$(COLOR_GREEN)Tidying modules...$(COLOR_RESET)"
262-
@$(GOMOD) tidy
263-
@echo "$(COLOR_GREEN)✓ Modules tidied$(COLOR_RESET)"
308+
@echo "$(COLOR_GREEN)Tidying all modules...$(COLOR_RESET)"
309+
@COUNT=0; \
310+
ROOT_DIR=$$(pwd); \
311+
for modfile in $$(find . -name "go.mod" -type f | grep -v "/vendor/" | sort); do \
312+
dir=$$(dirname $$modfile); \
313+
echo " Tidying $$dir..."; \
314+
cd "$$ROOT_DIR/$$dir" && $(GOMOD) tidy; \
315+
COUNT=$$((COUNT + 1)); \
316+
done; \
317+
cd "$$ROOT_DIR"; \
318+
echo "$(COLOR_GREEN)✓ Tidied $$COUNT modules$(COLOR_RESET)"
264319

265320
.PHONY: tidy-check
266321
## tidy-check: Check if go.mod is tidy

cmd/forge/plugins/dev_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func main() {}`
322322
config: &config.ForgeConfig{
323323
RootDir: tmpDir,
324324
Project: config.ProjectConfig{
325-
Structure: config.StructureConfig{
325+
Structure: &config.StructureConfig{
326326
Cmd: "cmd",
327327
},
328328
},

cmd/forge/plugins/generate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func TestDiscoverTargets(t *testing.T) {
113113
RootDir: tmpDir,
114114
Project: config.ProjectConfig{
115115
Layout: "single-module",
116-
Structure: config.StructureConfig{
116+
Structure: &config.StructureConfig{
117117
Cmd: "cmd",
118118
},
119119
},
@@ -162,7 +162,7 @@ func TestDiscoverTargetsNoApps(t *testing.T) {
162162
RootDir: tmpDir,
163163
Project: config.ProjectConfig{
164164
Layout: "single-module",
165-
Structure: config.StructureConfig{
165+
Structure: &config.StructureConfig{
166166
Cmd: "cmd",
167167
},
168168
},

examples/cors_preflight/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func main() {
2424
// This will automatically handle OPTIONS preflight requests
2525
corsConfig := middleware.CORSConfig{
2626
AllowOrigins: []string{
27-
"http://localhost:3000", // React dev server
28-
"http://localhost:5173", // Vite dev server
27+
"http://localhost:3000", // React dev server
28+
"http://localhost:5173", // Vite dev server
2929
"https://app.example.com", // Production frontend
3030
},
3131
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
@@ -119,4 +119,3 @@ func main() {
119119
log.Fatal(err)
120120
}
121121
}
122-

examples/optional_tag/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,3 @@ func main() {
216216
log.Fatal(err)
217217
}
218218
}
219-

extensions/ai/examples/ai-agents-demo/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func main() {
3131
})
3232

3333
// Create AI extension with production config
34-
var ext *ai.Extension
34+
var ext forge.Extension
3535
if usePostgres {
3636
fmt.Println("\n✓ Using PostgreSQL for persistence")
3737
ext = ai.NewExtension(
@@ -143,7 +143,7 @@ func main() {
143143
Config: map[string]interface{}{},
144144
}
145145

146-
anomalyAgent, err := agentMgr.CreateAgent(ctx, anomalyDef)
146+
_, err = agentMgr.CreateAgent(ctx, anomalyDef)
147147
if err != nil {
148148
log.Printf(" Error creating anomaly agent: %v", err)
149149
} else {
@@ -163,7 +163,7 @@ func main() {
163163
Config: map[string]interface{}{},
164164
}
165165

166-
schedulerAgent, err := agentMgr.CreateAgent(ctx, schedulerDef)
166+
_, err = agentMgr.CreateAgent(ctx, schedulerDef)
167167
if err != nil {
168168
log.Printf(" Error creating scheduler agent: %v", err)
169169
} else {

extensions/ai/inference/examples/batch_inference.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build ignore
2+
13
package main
24

35
import (

extensions/ai/inference/examples/pipeline_example.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build ignore
2+
13
package main
24

35
import (

extensions/ai/inference/examples/pytorch_serving.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build ignore
2+
13
package main
24

35
import (
@@ -52,26 +54,26 @@ func main() {
5254
// 3. Add text preprocessing pipeline
5355
engine.AddPreprocessor(func(ctx context.Context, req inference.InferenceRequest) (inference.InferenceRequest, error) {
5456
fmt.Printf(" → Tokenizing input for request %s\n", req.ID)
55-
57+
5658
// Text preprocessing:
5759
// - Tokenization
5860
// - Padding/truncation
5961
// - Convert to tensor format
6062
req.Input = tokenizeText(req.Input)
61-
63+
6264
return req, nil
6365
})
6466

6567
// 4. Add output formatting
6668
engine.AddPostprocessor(func(ctx context.Context, resp inference.InferenceResponse) (inference.InferenceResponse, error) {
6769
fmt.Printf(" ← Formatting output for response %s\n", resp.ID)
68-
70+
6971
// Output postprocessing:
7072
// - Apply softmax
7173
// - Get top-k predictions
7274
// - Format as human-readable labels
7375
resp.Output = formatClassificationOutput(resp.Output)
74-
76+
7577
return resp, nil
7678
})
7779

@@ -128,16 +130,16 @@ func main() {
128130
// loadPyTorchModel loads a PyTorch model (via ONNX Runtime)
129131
func loadPyTorchModel(path string) models.Model {
130132
// Example stub - replace with actual ONNX loading:
131-
//
133+
//
132134
// import "github.com/yalue/onnxruntime_go"
133-
//
135+
//
134136
// session, err := onnxruntime_go.NewSession(path)
135137
// if err != nil {
136138
// return nil
137139
// }
138-
//
140+
//
139141
// return &ONNXModelWrapper{session: session}
140-
142+
141143
return &MockPyTorchModel{name: "text-classifier"}
142144
}
143145

@@ -149,7 +151,7 @@ type MockPyTorchModel struct {
149151
func (m *MockPyTorchModel) Predict(ctx context.Context, input interface{}) (interface{}, error) {
150152
// Simulate model inference with GPU latency
151153
time.Sleep(20 * time.Millisecond)
152-
154+
153155
return map[string]float64{
154156
"positive": 0.78,
155157
"negative": 0.15,
@@ -181,7 +183,7 @@ func (s *ModelAwareBatchingStrategy) ShouldBatch(req inference.InferenceRequest,
181183
if batch.ModelID != req.ModelID {
182184
return false
183185
}
184-
186+
185187
// Batch if we haven't reached optimal size
186188
return batch.Size < s.optimalBatchSize
187189
}
@@ -216,9 +218,9 @@ func formatClassificationOutput(output interface{}) interface{} {
216218
func simulateLoad(ctx context.Context, engine *inference.InferenceEngine, reqPerSec int, duration time.Duration) {
217219
ticker := time.NewTicker(time.Second / time.Duration(reqPerSec))
218220
defer ticker.Stop()
219-
221+
220222
done := time.After(duration)
221-
223+
222224
for {
223225
select {
224226
case <-done:

extensions/ai/inference/examples/tensorflow_serving.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build ignore
2+
13
package main
24

35
import (
@@ -59,12 +61,12 @@ func main() {
5961
// - Resize images to 224x224
6062
// - Normalize pixel values to [0, 1]
6163
// - Convert to model input format
62-
64+
6365
fmt.Printf(" → Preprocessing request %s\n", req.ID)
64-
66+
6567
// Your preprocessing logic here
6668
req.Input = preprocessImage(req.Input)
67-
69+
6870
return req, nil
6971
})
7072

@@ -74,12 +76,12 @@ func main() {
7476
// - Convert logits to probabilities
7577
// - Apply confidence threshold
7678
// - Format output labels
77-
79+
7880
fmt.Printf(" ← Postprocessing response %s\n", resp.ID)
79-
81+
8082
// Your postprocessing logic here
8183
resp.Output = postprocessOutput(resp.Output)
82-
84+
8385
return resp, nil
8486
})
8587

@@ -113,7 +115,7 @@ func main() {
113115
// Batch of requests (will be automatically batched)
114116
fmt.Println("\nSending batch of 20 requests...")
115117
start := time.Now()
116-
118+
117119
for i := 0; i < 20; i++ {
118120
go func(idx int) {
119121
result, err := engine.Infer(ctx, inference.InferenceRequest{
@@ -127,14 +129,14 @@ func main() {
127129
}
128130
}(i)
129131
}
130-
132+
131133
time.Sleep(2 * time.Second) // Wait for batch processing
132-
134+
133135
fmt.Printf("\nBatch completed in %v\n", time.Since(start))
134136

135137
// 7. Display statistics
136138
fmt.Println("\n--- Engine Statistics ---\n")
137-
139+
138140
stats := engine.Stats()
139141
fmt.Printf("Requests Processed: %d\n", stats.RequestsProcessed)
140142
fmt.Printf("Batches Processed: %d\n", stats.BatchesProcessed)
@@ -156,16 +158,16 @@ func main() {
156158
// Replace with actual TensorFlow loading logic
157159
func loadTensorFlowModel(path string) models.Model {
158160
// Example stub - replace with actual TensorFlow model loading:
159-
//
161+
//
160162
// import tf "github.com/tensorflow/tensorflow/tensorflow/go"
161-
//
163+
//
162164
// model, err := tf.LoadSavedModel(path, []string{"serve"}, nil)
163165
// if err != nil {
164166
// return nil
165167
// }
166-
//
168+
//
167169
// return &TensorFlowModelWrapper{model: model}
168-
170+
169171
return &MockModel{name: "image-classifier"}
170172
}
171173

0 commit comments

Comments
 (0)