init
This commit is contained in:
commit
e1909b04b2
16 changed files with 448 additions and 0 deletions
57
main.go
Normal file
57
main.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue