leech/main.go

40 lines
764 B
Go
Raw Normal View History

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",
}))
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-28 00:48:16 +02:00
app.Static("/serve/"+dirName, dirToServe)
2024-04-27 12:16:43 +02:00
}
2024-06-10 21:36:26 +02:00
app.Use("/thumb", route.HandleThumb)
2024-04-28 00:45:42 +02:00
app.Use("/", route.HandleList)
2024-04-27 12:40:07 +02:00
app.Listen(config.Config.Host)
2024-04-27 12:16:43 +02:00
}