Tinkering with how to do a 'check view, then static' style of templates, but maybe I need to do a generator?

main
Zed A. Shaw 2 weeks ago
parent abc9fbda2e
commit b9d5dbb2e9
  1. 23
      api/controllers.go
  2. 8
      main.go
  3. 0
      views/test.html

@ -2,6 +2,7 @@ package api
import (
"log"
"time"
"github.com/gofiber/fiber/v2"
_ "github.com/mattn/go-sqlite3"
@ -112,6 +113,23 @@ func PostApiLink(c *fiber.Ctx) error {
func Setup(app *fiber.App) {
STORE = session.New()
app.Static("/", "./public", fiber.Static{
Compress: false,
CacheDuration: 1 * time.Nanosecond,
Next: func(c *fiber.Ctx) bool {
// true means skip, so I can check if the url matches
// a view, and if it does then skip which will leave
// it to the view handler next
return false
},
})
app.Get("/v/:name/", func (c *fiber.Ctx) error {
return c.Render(c.Params("name"), fiber.Map{
"Title": "Hello, World!",
})
})
app.Get("/api/stream", GetApiStream)
app.Get("/api/logout", GetApiLogout)
app.Get("/api/stream/:id", GetApiStreamId)
@ -120,11 +138,6 @@ func Setup(app *fiber.App) {
app.Post("/api/link", PostApiLink)
app.Post("/api/register", PostApiRegister)
app.Get("/test/:name/", func (c *fiber.Ctx) error {
return c.Render(c.Params("name"), fiber.Map{
"Title": "Hello, World!",
})
})
}

@ -3,7 +3,6 @@ package main
import (
"log"
"os"
"time"
"os/signal"
"syscall"
"github.com/gofiber/fiber/v2"
@ -25,6 +24,8 @@ func main() {
app := fiber.New(fiber.Config{
Views: engine,
ViewsLayout: "layouts/main",
CaseSensitive: true,
StrictRouting: true,
})
app.Use(logger.New())
@ -33,11 +34,6 @@ func main() {
api.Setup(app)
data.Setup("sqlite3", "db.sqlite3")
app.Static("/", "./public", fiber.Static{
Compress: true,
CacheDuration: 1 * time.Nanosecond,
})
// this sets up graceful shutdown
go func() {
if err := app.Listen(":5001"); err != nil {

Loading…
Cancel
Save