57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package main // import "git.sapphic.engineer/roleypoly/v4"
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/goccy/go-json"
|
|
"github.com/gofiber/fiber/v3"
|
|
"github.com/gofiber/fiber/v3/middleware/session"
|
|
"github.com/gofiber/storage/pebble/v2"
|
|
"github.com/gofiber/template/html/v2"
|
|
)
|
|
|
|
func main() {
|
|
storageDir := getStorageDirectory()
|
|
|
|
viewEngine := html.New("./templates", ".html")
|
|
|
|
app := fiber.New(fiber.Config{
|
|
JSONEncoder: json.Marshal,
|
|
JSONDecoder: json.Unmarshal,
|
|
Views: viewEngine,
|
|
ViewsLayout: "main",
|
|
})
|
|
|
|
app.Use(session.New(session.Config{
|
|
Storage: pebble.New(pebble.Config{
|
|
Path: storageDir + "/sessions",
|
|
}),
|
|
}))
|
|
|
|
listenAddr := os.Getenv("LISTEN_ADDR")
|
|
if listenAddr == "" {
|
|
listenAddr = ":8169"
|
|
}
|
|
|
|
log.Fatal(app.Listen(listenAddr))
|
|
}
|
|
|
|
func getStorageDirectory() string {
|
|
path := os.Getenv("STORAGE_DIR")
|
|
if path == "" {
|
|
path = "./.storage"
|
|
}
|
|
|
|
_, err := os.Stat(path)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
err := os.MkdirAll(path, 0744)
|
|
if err != nil {
|
|
log.Fatalln("failed to create storage directory: ", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
return path
|
|
}
|