diff options
| -rw-r--r-- | handlers/analyze.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/handlers/analyze.go b/handlers/analyze.go new file mode 100644 index 0000000..6943981 --- /dev/null +++ b/handlers/analyze.go @@ -0,0 +1,49 @@ +package handlers
+
+import (
+ "complexity-analyzer/services"
+
+ "github.com/gofiber/fiber/v2"
+)
+
+type AnalyzeRequest struct {
+ Code string `json:"code"`
+ Language string `json:"language"`
+}
+
+type AnalyzeResponse struct {
+ Complexity string `json:"complexity"`
+ Confidence float64 `json:"confidence"`
+ StaticAnalysis []string `json:"staticAnalysis"`
+ PerformanceData []PerformancePoint `json:"performanceData"`
+ Error string `json:"error,omitempty"`
+}
+
+type PerformancePoint struct {
+ Size int `json:"size"`
+ Time float64 `json:"time"`
+}
+
+func AnalyzeCode(c *fiber.Ctx) error {
+ var req AnalyzeRequest
+ if err := c.BodyParser(&req); err != nil {
+ return c.Status(400).JSON(fiber.Map{
+ "error": "Invalid request body",
+ })
+ }
+
+ if req.Code == "" {
+ return c.Status(400).JSON(fiber.Map{
+ "error": "Code is required",
+ })
+ }
+
+ result, err := services.AnalyzeWithGemini(req.Code, req.Language)
+ if err != nil {
+ return c.Status(500).JSON(fiber.Map{
+ "error": err.Error(),
+ })
+ }
+
+ return c.JSON(result)
+}
|
