aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: f83a439992bffd4e52ecf88e385ce7b2e39d6e92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main

import (
	"complexity-analyzer/handlers"
	"log"

	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/cors"
	"github.com/gofiber/fiber/v2/middleware/logger"
	"github.com/gofiber/template/html/v2"
	"github.com/joho/godotenv"
)

func main() {
	// Load .env file
	if err := godotenv.Load(); err != nil {
		log.Println("No .env file found, using system environment variables")
	}

	// Initialize template engine
	engine := html.New("./templates", ".html")

	app := fiber.New(fiber.Config{
		Views:     engine,
		BodyLimit: 10 * 1024 * 1024,
	})

	// Middleware
	app.Use(logger.New())
	app.Use(cors.New())

	// Static files
	app.Static("/css", "./static/css")
	app.Static("/js", "./static/js")

	// Routes
	app.Get("/", func(c *fiber.Ctx) error {
		return c.Render("index", fiber.Map{
			"Title": "Algorithm Complexity Analyzer",
		})
	})

	// API routes
	api := app.Group("/api")
	api.Post("/analyze", handlers.AnalyzeCode)

	log.Println("Server starting on http://localhost:3000")
	log.Fatal(app.Listen(":3000"))
}