leech/main.go

43 lines
932 B
Go
Raw Permalink Normal View History

2024-04-27 12:16:43 +02:00
package main
import (
2024-04-27 12:25:21 +02:00
"embed"
"fmt"
2024-04-27 12:16:43 +02:00
"leech/config"
"leech/route"
2024-04-27 12:25:21 +02:00
"net/http"
"net/url"
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 {
fmt.Println("Registering route /serve/" + url.QueryEscape(dirName))
app.Static("/serve/"+url.QueryEscape(dirName), dirToServe) // For some reason this doesn't work and this is not my fault.
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
}