-
Notifications
You must be signed in to change notification settings - Fork 62
added all logging middleware files #42
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
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 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,12 +18,16 @@ import ( | |||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| "gateway/middleware" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| "github.com/gin-contrib/cors" | ||||||||||||||||||||||||||||
| "github.com/gin-gonic/gin" | ||||||||||||||||||||||||||||
| "github.com/google/uuid" | ||||||||||||||||||||||||||||
| "github.com/joho/godotenv" | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /* -------------------- Types -------------------- */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| type PaymentContext struct { | ||||||||||||||||||||||||||||
| Recipient string `json:"recipient"` | ||||||||||||||||||||||||||||
| Token string `json:"token"` | ||||||||||||||||||||||||||||
|
|
@@ -47,6 +51,10 @@ type SummarizeRequest struct { | |||||||||||||||||||||||||||
| Text string `json:"text"` | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /* -------------------- Main -------------------- */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| func main() { | ||||||||||||||||||||||||||||
| _ = godotenv.Load("../.env") | ||||||||||||||||||||||||||||
| func validateConfig() error { | ||||||||||||||||||||||||||||
| required := []string{ | ||||||||||||||||||||||||||||
| "OPENROUTER_API_KEY", | ||||||||||||||||||||||||||||
|
|
@@ -106,32 +114,14 @@ func main() { | |||||||||||||||||||||||||||
| fmt.Println("[WARN] CHAIN_ID not set, using default: 8453(base)") | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| r := gin.Default() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| r.StaticFile("/openapi.yaml", "openapi.yaml") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| r.GET("/docs", func(c *gin.Context) { | ||||||||||||||||||||||||||||
| c.Header("Content-Type", "text/html") | ||||||||||||||||||||||||||||
| c.String(200, ` | ||||||||||||||||||||||||||||
| <!DOCTYPE html> | ||||||||||||||||||||||||||||
| <html> | ||||||||||||||||||||||||||||
| <head> | ||||||||||||||||||||||||||||
| <title>MicroAI Paygate Docs</title> | ||||||||||||||||||||||||||||
| <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui.css" /> | ||||||||||||||||||||||||||||
| </head> | ||||||||||||||||||||||||||||
| <body> | ||||||||||||||||||||||||||||
| <div id="swagger-ui"></div> | ||||||||||||||||||||||||||||
| <script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-bundle.js"></script> | ||||||||||||||||||||||||||||
| <script> | ||||||||||||||||||||||||||||
| SwaggerUIBundle({ | ||||||||||||||||||||||||||||
| url: '/openapi.yaml', | ||||||||||||||||||||||||||||
| dom_id: '#swagger-ui' | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| </script> | ||||||||||||||||||||||||||||
| </body> | ||||||||||||||||||||||||||||
| </html> | ||||||||||||||||||||||||||||
| `) | ||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||
| // Init structured logging | ||||||||||||||||||||||||||||
| middleware.InitLogger() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| r := gin.New() | ||||||||||||||||||||||||||||
| r.Use( | ||||||||||||||||||||||||||||
| gin.Recovery(), | ||||||||||||||||||||||||||||
| middleware.RequestLogger(), | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| r.Use(cors.New(cors.Config{ | ||||||||||||||||||||||||||||
| AllowOrigins: []string{"http://localhost:3001"}, | ||||||||||||||||||||||||||||
|
|
@@ -171,6 +161,15 @@ func main() { | |||||||||||||||||||||||||||
| r.Run(":" + port) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /* -------------------- Handlers -------------------- */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| func handleHealth(c *gin.Context) { | ||||||||||||||||||||||||||||
| c.JSON(http.StatusOK, gin.H{ | ||||||||||||||||||||||||||||
| "status": "ok", | ||||||||||||||||||||||||||||
| "service": "gateway", | ||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+232
to
+237
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Either remove this function or rename it to Prompt To Fix With AIThis is a comment left during a code review.
Path: gateway/main.go
Line: 232:237
Comment:
`handleHealth()` function is defined but never used. The actual health check endpoint uses `handleHealthz()` on line 186.
Either remove this function or rename it to `handleHealthz()` and remove the duplicate definition on line 980.
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // handleSummarize handles POST /api/ai/summarize requests. It validates | ||||||||||||||||||||||||||||
| // payment headers, calls the verifier service to validate the signature, and | ||||||||||||||||||||||||||||
| // forwards the text to the AI service. The handler respects context timeouts | ||||||||||||||||||||||||||||
|
|
@@ -180,8 +179,13 @@ func handleSummarize(c *gin.Context) { | |||||||||||||||||||||||||||
| signature := c.GetHeader("X-402-Signature") | ||||||||||||||||||||||||||||
| nonce := c.GetHeader("X-402-Nonce") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // 1. Payment Required | ||||||||||||||||||||||||||||
| if signature == "" || nonce == "" { | ||||||||||||||||||||||||||||
| c.Set("payment_verified", false) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| ctx := createPaymentContext() | ||||||||||||||||||||||||||||
| c.JSON(402, gin.H{ | ||||||||||||||||||||||||||||
| "error": "Payment Required", | ||||||||||||||||||||||||||||
| "paymentContext": ctx, | ||||||||||||||||||||||||||||
| paymentContext := createPaymentContext() | ||||||||||||||||||||||||||||
| c.JSON(402, gin.H{ | ||||||||||||||||||||||||||||
| "error": "Payment Required", | ||||||||||||||||||||||||||||
|
|
@@ -191,6 +195,21 @@ func handleSummarize(c *gin.Context) { | |||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
253
to
269
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge conflict: incomplete payment verification logic duplicated with syntax errors. Line 260 declares
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: gateway/main.go
Line: 253:269
Comment:
Merge conflict: incomplete payment verification logic duplicated with syntax errors. Line 260 declares `ctx` but tries to assign `paymentContext` (undefined), and lines 261-269 duplicate the logic from lines 262-268.
```suggestion
signature := c.GetHeader("X-402-Signature")
nonce := c.GetHeader("X-402-Nonce")
if signature == "" || nonce == "" {
c.Set("payment_verified", false)
c.JSON(402, gin.H{
"error": "Payment Required",
"message": "Please sign the payment context",
"paymentContext": createPaymentContext(),
})
return
}
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| verifyReq := VerifyRequest{ | ||||||||||||||||||||||||||||
| Context: PaymentContext{ | ||||||||||||||||||||||||||||
| Recipient: getRecipientAddress(), | ||||||||||||||||||||||||||||
| Token: "USDC", | ||||||||||||||||||||||||||||
| Amount: getPaymentAmount(), | ||||||||||||||||||||||||||||
| Nonce: nonce, | ||||||||||||||||||||||||||||
| ChainID: getChainID(), | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| Signature: signature, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| body, _ := json.Marshal(verifyReq) | ||||||||||||||||||||||||||||
| resp, err := http.Post("http://127.0.0.1:3002/verify", "application/json", bytes.NewBuffer(body)) | ||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||
| c.JSON(500, gin.H{"error": "verifier unavailable"}) | ||||||||||||||||||||||||||||
|
Comment on lines
+271
to
+285
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Duplicate verification request code - remove the first block. Lines 198-212 contain an incomplete verification request implementation using Remove the first block (lines 198-212) and keep only the second implementation. 🤖 Prompt for AI Agents
Comment on lines
+271
to
+285
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge conflict: duplicate payment verification code that conflicts with the refactored Delete this entire conflicted section - the correct implementation uses Prompt To Fix With AIThis is a comment left during a code review.
Path: gateway/main.go
Line: 271:285
Comment:
Merge conflict: duplicate payment verification code that conflicts with the refactored `verifyPayment()` function used later. Lines 271-285 make a direct HTTP call without using context, missing error handling (line 285 has no `return`), and this code block is unreachable due to the `return` on line 268.
Delete this entire conflicted section - the correct implementation uses `verifyPayment()` on line 311.
How can I resolve this? If you propose a fix, please make it concise.
Comment on lines
+284
to
+285
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: gateway/main.go
Line: 284:285
Comment:
Missing `return` statement after sending error response.
```suggestion
resp, err := http.Post("http://127.0.0.1:3002/verify", "application/json", bytes.NewBuffer(body))
if err != nil {
c.JSON(500, gin.H{"error": "verifier unavailable"})
return
}
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||
| // 2. Verify Payment (Call Rust Service) | ||||||||||||||||||||||||||||
| paymentCtx := PaymentContext{ | ||||||||||||||||||||||||||||
| Recipient: getRecipientAddress(), | ||||||||||||||||||||||||||||
|
|
@@ -241,25 +260,26 @@ func handleSummarize(c *gin.Context) { | |||||||||||||||||||||||||||
| defer resp.Body.Close() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| var verifyResp VerifyResponse | ||||||||||||||||||||||||||||
| if err := json.NewDecoder(resp.Body).Decode(&verifyResp); err != nil { | ||||||||||||||||||||||||||||
| c.JSON(500, gin.H{"error": "Failed to decode verification response"}) | ||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| _ = json.NewDecoder(resp.Body).Decode(&verifyResp) | ||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silently ignoring JSON decode error can mask verification failures. The decode error is discarded with 🔎 Proposed fix- _ = json.NewDecoder(resp.Body).Decode(&verifyResp)
+ if err := json.NewDecoder(resp.Body).Decode(&verifyResp); err != nil {
+ log.Printf("error decoding verifier response: %v", err)
+ c.JSON(500, gin.H{"error": "Invalid verifier response"})
+ return
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if !verifyResp.IsValid { | ||||||||||||||||||||||||||||
| c.JSON(403, gin.H{"error": "Invalid Signature", "details": verifyResp.Error}) | ||||||||||||||||||||||||||||
| c.Set("payment_verified", false) | ||||||||||||||||||||||||||||
| c.JSON(403, gin.H{"error": "invalid signature"}) | ||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // 3. Call AI Service | ||||||||||||||||||||||||||||
| c.Set("payment_verified", true) | ||||||||||||||||||||||||||||
| c.Set("user_wallet", verifyResp.RecoveredAddress) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| var req SummarizeRequest | ||||||||||||||||||||||||||||
| if err := c.BindJSON(&req); err != nil { | ||||||||||||||||||||||||||||
| c.JSON(400, gin.H{"error": "Invalid request body"}) | ||||||||||||||||||||||||||||
| c.JSON(400, gin.H{"error": "invalid body"}) | ||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||
|
Comment on lines
+414
to
+428
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge conflict: unreachable duplicate code inside Delete this entire section - the correct return logic is on line 433. Prompt To Fix With AIThis is a comment left during a code review.
Path: gateway/main.go
Line: 414:428
Comment:
Merge conflict: unreachable duplicate code inside `verifyPayment()` function. Lines 414-428 reference `c.Set()`, `c.JSON()`, and `c.BindJSON()` but `c` (gin.Context) is not available in this function - it takes `context.Context`, not `gin.Context`.
Delete this entire section - the correct return logic is on line 433.
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| summary, err := callOpenRouter(c.Request.Context(), req.Text) | ||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||
| c.JSON(500, gin.H{"error": err.Error()}) | ||||||||||||||||||||||||||||
| // If the error was due to a timeout, return 504 | ||||||||||||||||||||||||||||
| if errors.Is(err, context.DeadlineExceeded) || c.Request.Context().Err() == context.DeadlineExceeded { | ||||||||||||||||||||||||||||
| c.JSON(504, gin.H{"error": "Gateway Timeout", "message": "AI request timed out"}) | ||||||||||||||||||||||||||||
|
|
@@ -272,7 +292,8 @@ func handleSummarize(c *gin.Context) { | |||||||||||||||||||||||||||
| c.JSON(200, gin.H{"result": summary}) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // createPaymentContext constructs a PaymentContext prefilled with the recipient address (from RECIPIENT_ADDRESS or a fallback), the USDC token, amount "0.001", a newly generated UUID nonce, and chain ID 8453. | ||||||||||||||||||||||||||||
| /* -------------------- Helpers -------------------- */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| func createPaymentContext() PaymentContext { | ||||||||||||||||||||||||||||
| return PaymentContext{ | ||||||||||||||||||||||||||||
| Recipient: getRecipientAddress(), | ||||||||||||||||||||||||||||
|
|
@@ -283,42 +304,37 @@ func createPaymentContext() PaymentContext { | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // getRecipientAddress retrieves the recipient address from the RECIPIENT_ADDRESS environment variable. | ||||||||||||||||||||||||||||
| // If RECIPIENT_ADDRESS is unset, it logs a warning and returns the default address "0x2cAF48b4BA1C58721a85dFADa5aC01C2DFa62219". | ||||||||||||||||||||||||||||
| func getRecipientAddress() string { | ||||||||||||||||||||||||||||
| addr := os.Getenv("RECIPIENT_ADDRESS") | ||||||||||||||||||||||||||||
| if addr == "" { | ||||||||||||||||||||||||||||
| log.Println("Warning: RECIPIENT_ADDRESS not set, using default") | ||||||||||||||||||||||||||||
| return "0x2cAF48b4BA1C58721a85dFADa5aC01C2DFa62219" | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| return addr | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // getPaymentAmount returns the payment amount from the PAYMENT_AMOUNT environment variable. | ||||||||||||||||||||||||||||
| // If unset, it defaults to "0.001". | ||||||||||||||||||||||||||||
| func getPaymentAmount() string { | ||||||||||||||||||||||||||||
| amount := os.Getenv("PAYMENT_AMOUNT") | ||||||||||||||||||||||||||||
| if amount == "" { | ||||||||||||||||||||||||||||
| a := os.Getenv("PAYMENT_AMOUNT") | ||||||||||||||||||||||||||||
| if a == "" { | ||||||||||||||||||||||||||||
| return "0.001" | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| return amount | ||||||||||||||||||||||||||||
| return a | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // getChainID returns the blockchain chain ID from the CHAIN_ID environment variable. | ||||||||||||||||||||||||||||
| // If unset or invalid, it defaults to 8453 (Base). | ||||||||||||||||||||||||||||
| func getChainID() int { | ||||||||||||||||||||||||||||
| chainIDStr := os.Getenv("CHAIN_ID") | ||||||||||||||||||||||||||||
| if chainIDStr == "" { | ||||||||||||||||||||||||||||
| id := os.Getenv("CHAIN_ID") | ||||||||||||||||||||||||||||
| if id == "" { | ||||||||||||||||||||||||||||
| return 8453 | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| chainID, err := strconv.Atoi(chainIDStr) | ||||||||||||||||||||||||||||
| n, err := strconv.Atoi(id) | ||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||
| log.Printf("Warning: Invalid CHAIN_ID '%s', using default 8453", chainIDStr) | ||||||||||||||||||||||||||||
| return 8453 | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| return chainID | ||||||||||||||||||||||||||||
| return n | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| func callOpenRouter(text string) (string, error) { | ||||||||||||||||||||||||||||
| if text == "" { | ||||||||||||||||||||||||||||
| return "", fmt.Errorf("empty text") | ||||||||||||||||||||||||||||
| // callOpenRouter sends the given text to the OpenRouter chat completions API | ||||||||||||||||||||||||||||
| // requesting a two-sentence summary and returns the generated summary. | ||||||||||||||||||||||||||||
| // It reads OPENROUTER_API_KEY for authorization and OPENROUTER_MODEL to select | ||||||||||||||||||||||||||||
|
|
@@ -364,32 +380,7 @@ func callOpenRouter(ctx context.Context, text string) (string, error) { | |||||||||||||||||||||||||||
| if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { | ||||||||||||||||||||||||||||
| return "", fmt.Errorf("failed to decode AI response: %w", err) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| choices, ok := result["choices"].([]interface{}) | ||||||||||||||||||||||||||||
| if !ok || len(choices) == 0 { | ||||||||||||||||||||||||||||
| return "", fmt.Errorf("invalid response from AI provider: no choices") | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| choice, ok := choices[0].(map[string]interface{}) | ||||||||||||||||||||||||||||
| if !ok { | ||||||||||||||||||||||||||||
| return "", fmt.Errorf("invalid response from AI provider: malformed choice") | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| message, ok := choice["message"].(map[string]interface{}) | ||||||||||||||||||||||||||||
| if !ok { | ||||||||||||||||||||||||||||
| return "", fmt.Errorf("invalid response from AI provider: malformed message") | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| content, ok := message["content"].(string) | ||||||||||||||||||||||||||||
| if !ok { | ||||||||||||||||||||||||||||
| return "", fmt.Errorf("invalid response from AI provider: missing content") | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return content, nil | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| func handleHealth(c *gin.Context) { | ||||||||||||||||||||||||||||
| c.JSON(http.StatusOK, gin.H{"status": "ok", "service": "gateway"}) | ||||||||||||||||||||||||||||
| return "stub summary", nil | ||||||||||||||||||||||||||||
|
Comment on lines
523
to
+577
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge conflict: duplicate Delete the stub function (lines 523-525) and the unreachable return (line 577). Prompt To Fix With AIThis is a comment left during a code review.
Path: gateway/main.go
Line: 523:577
Comment:
Merge conflict: duplicate `callOpenRouter()` function definition. Lines 523-525 define a stub version that returns `"stub summary"`, while lines 526-600 contain the full implementation. The stub will never execute and line 577 `return "stub summary", nil` is unreachable dead code.
Delete the stub function (lines 523-525) and the unreachable return (line 577).
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Rate Limiting Functions | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package middleware | ||
|
|
||
| import ( | ||
| "os" | ||
| "time" | ||
|
|
||
| "github.com/gin-gonic/gin" | ||
| "github.com/rs/zerolog" | ||
| "github.com/rs/zerolog/log" | ||
| ) | ||
|
|
||
| // InitLogger initializes zerolog with level from LOG_LEVEL env var | ||
| func InitLogger() { | ||
| level := os.Getenv("LOG_LEVEL") | ||
| if level == "" { | ||
| level = "info" | ||
| } | ||
|
|
||
| parsedLevel, err := zerolog.ParseLevel(level) | ||
| if err != nil { | ||
| parsedLevel = zerolog.InfoLevel | ||
| } | ||
|
|
||
| zerolog.SetGlobalLevel(parsedLevel) | ||
|
|
||
| log.Logger = zerolog.New(os.Stdout). | ||
| With(). | ||
| Timestamp(). | ||
| Logger() | ||
| } | ||
|
|
||
| // RequestLogger is a Gin middleware that logs each request in JSON | ||
| func RequestLogger() gin.HandlerFunc { | ||
| return func(c *gin.Context) { | ||
| start := time.Now() | ||
|
|
||
| // Process request | ||
| c.Next() | ||
|
|
||
| latency := time.Since(start) | ||
|
|
||
| // Optional values set by handlers | ||
| paymentVerified, _ := c.Get("payment_verified") | ||
| userWallet, _ := c.Get("user_wallet") | ||
|
|
||
| log.Info(). | ||
| Str("method", c.Request.Method). | ||
| Str("path", c.Request.URL.Path). | ||
| Int("status", c.Writer.Status()). | ||
| Int64("latency_ms", latency.Milliseconds()). | ||
| Str("client_ip", c.ClientIP()). | ||
| Interface("payment_verified", paymentVerified). | ||
| Interface("user_wallet", userWallet). | ||
| Msg("request completed") | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,10 @@ | ||||||
| module microai-paygate | ||||||
|
|
||||||
| go 1.25.5 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invalid Go version
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: go.mod
Line: 3:3
Comment:
Invalid Go version `1.25.5`. The latest Go version is 1.23.x (as of early 2025). Valid format is `go 1.23` or similar.
```suggestion
go 1.23
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||
|
|
||||||
| require ( | ||||||
| github.com/mattn/go-colorable v0.1.13 // indirect | ||||||
| github.com/mattn/go-isatty v0.0.19 // indirect | ||||||
| github.com/rs/zerolog v1.34.0 // indirect | ||||||
| golang.org/x/sys v0.12.0 // indirect | ||||||
| ) | ||||||
|
Comment on lines
+1
to
+10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This root-level Delete this file entirely - Go dependencies are already properly managed in Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: go.mod
Line: 1:10
Comment:
This root-level `go.mod` shouldn't exist. The project structure shows this is a monorepo with separate modules (`gateway/go.mod`, `verifier/Cargo.toml`, `web/package.json`). The zerolog dependency should only be in `gateway/go.mod`, not at the root level.
Delete this file entirely - Go dependencies are already properly managed in `gateway/go.mod`.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
||||||
Uh oh!
There was an error while loading. Please reload this page.