2024-04-27 12:16:43 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-04-27 12:25:21 +02:00
|
|
|
"embed"
|
2024-04-27 12:16:43 +02:00
|
|
|
"leech/config"
|
|
|
|
"leech/route"
|
2024-04-27 12:25:21 +02:00
|
|
|
"net/http"
|
2024-04-27 12:16:43 +02:00
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
2024-04-27 12:25:21 +02:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
2024-04-27 12:16:43 +02:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
|
|
|
)
|
|
|
|
|
2024-04-27 12:25:21 +02:00
|
|
|
//go:embed assets/**
|
|
|
|
var assetsEmbed embed.FS
|
|
|
|
|
2024-04-27 12:16:43 +02:00
|
|
|
func main() {
|
2024-04-27 12:40:07 +02:00
|
|
|
config.Init()
|
2024-04-27 12:16:43 +02:00
|
|
|
app := fiber.New()
|
|
|
|
app.Use(logger.New(logger.Config{
|
|
|
|
Format: "[${ip}]:${port} ${status} - ${method} ${path}\n",
|
|
|
|
}))
|
|
|
|
app.Get("/:req", route.HandleList)
|
|
|
|
app.Get("/", route.HandleList)
|
|
|
|
|
2024-04-27 12:25:21 +02:00
|
|
|
app.Use("/assets", filesystem.New(filesystem.Config{
|
|
|
|
Root: http.FS(assetsEmbed),
|
|
|
|
PathPrefix: "assets",
|
|
|
|
Browse: true,
|
|
|
|
}))
|
2024-04-27 12:16:43 +02:00
|
|
|
|
2024-04-27 12:40:07 +02:00
|
|
|
for dirName, dirToServe := range config.Config.ServeDirs {
|
2024-04-27 12:16:43 +02:00
|
|
|
app.Static("/serve/"+dirName, dirToServe)
|
|
|
|
}
|
|
|
|
|
2024-04-27 12:40:07 +02:00
|
|
|
app.Listen(config.Config.Host)
|
2024-04-27 12:16:43 +02:00
|
|
|
}
|