-
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 1 commit
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 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,12 +9,16 @@ import ( | |||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||
| "strconv" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| "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"` | ||||||||||||||||||||||||||||
|
|
@@ -38,38 +42,19 @@ type SummarizeRequest struct { | |||||||||||||||||||||||||||
| Text string `json:"text"` | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /* -------------------- Main -------------------- */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| func main() { | ||||||||||||||||||||||||||||
| err := godotenv.Load("../.env") | ||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||
| log.Println("Warning: Error loading .env file") | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| _ = godotenv.Load("../.env") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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"}, | ||||||||||||||||||||||||||||
|
|
@@ -91,76 +76,78 @@ func main() { | |||||||||||||||||||||||||||
| r.Run(":" + port) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // - 500: Verifier or AI service failure (includes error details) | ||||||||||||||||||||||||||||
| /* -------------------- 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. |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| func handleSummarize(c *gin.Context) { | ||||||||||||||||||||||||||||
| signature := c.GetHeader("X-402-Signature") | ||||||||||||||||||||||||||||
| nonce := c.GetHeader("X-402-Nonce") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // 1. Payment Required | ||||||||||||||||||||||||||||
| if signature == "" || nonce == "" { | ||||||||||||||||||||||||||||
| context := createPaymentContext() | ||||||||||||||||||||||||||||
| c.Set("payment_verified", false) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| ctx := createPaymentContext() | ||||||||||||||||||||||||||||
| c.JSON(402, gin.H{ | ||||||||||||||||||||||||||||
| "error": "Payment Required", | ||||||||||||||||||||||||||||
| "message": "Please sign the payment context", | ||||||||||||||||||||||||||||
| "paymentContext": context, | ||||||||||||||||||||||||||||
| "paymentContext": ctx, | ||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||
| 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. |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // 2. Verify Payment (Call Rust Service) | ||||||||||||||||||||||||||||
| context := PaymentContext{ | ||||||||||||||||||||||||||||
| Recipient: getRecipientAddress(), | ||||||||||||||||||||||||||||
| Token: "USDC", | ||||||||||||||||||||||||||||
| Amount: getPaymentAmount(), | ||||||||||||||||||||||||||||
| Nonce: nonce, | ||||||||||||||||||||||||||||
| ChainID: getChainID(), | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| verifyReq := VerifyRequest{ | ||||||||||||||||||||||||||||
| Context: context, | ||||||||||||||||||||||||||||
| Context: PaymentContext{ | ||||||||||||||||||||||||||||
| Recipient: getRecipientAddress(), | ||||||||||||||||||||||||||||
| Token: "USDC", | ||||||||||||||||||||||||||||
| Amount: getPaymentAmount(), | ||||||||||||||||||||||||||||
| Nonce: nonce, | ||||||||||||||||||||||||||||
| ChainID: getChainID(), | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| Signature: signature, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| verifyBody, _ := json.Marshal(verifyReq) | ||||||||||||||||||||||||||||
| verifierURL := os.Getenv("VERIFIER_URL") | ||||||||||||||||||||||||||||
| if verifierURL == "" { | ||||||||||||||||||||||||||||
| verifierURL = "http://127.0.0.1:3002" | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| resp, err := http.Post(verifierURL+"/verify", "application/json", bytes.NewBuffer(verifyBody)) | ||||||||||||||||||||||||||||
| 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": "Verification service unavailable"}) | ||||||||||||||||||||||||||||
| 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. |
||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| 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(req.Text) | ||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||
| c.JSON(500, gin.H{"error": "AI Service Failed", "details": err.Error()}) | ||||||||||||||||||||||||||||
| c.JSON(500, gin.H{"error": err.Error()}) | ||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||
|
Comment on lines
+464
to
+471
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 error handling logic inside Delete lines 464-471 - correct error handling for Prompt To Fix With AIThis is a comment left during a code review.
Path: gateway/main.go
Line: 464:471
Comment:
Merge conflict: duplicate error handling logic inside `generateAndSendReceipt()`. Lines 464-471 duplicate timeout/error handling in a position that makes no sense (after marshaling receipt, before checking for error). This code is unreachable and conflicted.
Delete lines 464-471 - correct error handling for `json.Marshal(receipt)` is on line 472.
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
magic-peach marked this conversation as resolved.
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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(), | ||||||||||||||||||||||||||||
|
|
@@ -171,101 +158,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 | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // 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 | ||||||||||||||||||||||||||||
| // the model (defaults to "z-ai/glm-4.5-air:free" if unset). | ||||||||||||||||||||||||||||
| func callOpenRouter(text string) (string, error) { | ||||||||||||||||||||||||||||
| apiKey := os.Getenv("OPENROUTER_API_KEY") | ||||||||||||||||||||||||||||
| model := os.Getenv("OPENROUTER_MODEL") | ||||||||||||||||||||||||||||
| if model == "" { | ||||||||||||||||||||||||||||
| model = "z-ai/glm-4.5-air:free" | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| prompt := fmt.Sprintf("Summarize this text in 2 sentences: %s", text) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| reqBody, _ := json.Marshal(map[string]interface{}{ | ||||||||||||||||||||||||||||
| "model": model, | ||||||||||||||||||||||||||||
| "messages": []map[string]string{ | ||||||||||||||||||||||||||||
| {"role": "user", "content": prompt}, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| req, _ := http.NewRequest("POST", "https://openrouter.ai/api/v1/chat/completions", bytes.NewBuffer(reqBody)) | ||||||||||||||||||||||||||||
| req.Header.Set("Authorization", "Bearer "+apiKey) | ||||||||||||||||||||||||||||
| req.Header.Set("Content-Type", "application/json") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| client := &http.Client{} | ||||||||||||||||||||||||||||
| resp, err := client.Do(req) | ||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||
| return "", err | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| defer resp.Body.Close() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| var result map[string]interface{} | ||||||||||||||||||||||||||||
| if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { | ||||||||||||||||||||||||||||
| return "", fmt.Errorf("failed to decode AI response: %w", err) | ||||||||||||||||||||||||||||
| if text == "" { | ||||||||||||||||||||||||||||
| return "", fmt.Errorf("empty text") | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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. |
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.