Tinkering with how to do a 'check view, then static' style of templates, but maybe I need to do a generator?
This commit is contained in:
parent
abc9fbda2e
commit
b9d5dbb2e9
3 changed files with 20 additions and 11 deletions
|
@ -2,6 +2,7 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
@ -112,6 +113,23 @@ func PostApiLink(c *fiber.Ctx) error {
|
||||||
func Setup(app *fiber.App) {
|
func Setup(app *fiber.App) {
|
||||||
STORE = session.New()
|
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/stream", GetApiStream)
|
||||||
app.Get("/api/logout", GetApiLogout)
|
app.Get("/api/logout", GetApiLogout)
|
||||||
app.Get("/api/stream/:id", GetApiStreamId)
|
app.Get("/api/stream/:id", GetApiStreamId)
|
||||||
|
@ -120,11 +138,6 @@ func Setup(app *fiber.App) {
|
||||||
app.Post("/api/link", PostApiLink)
|
app.Post("/api/link", PostApiLink)
|
||||||
app.Post("/api/register", PostApiRegister)
|
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!",
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
main.go
8
main.go
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
@ -25,6 +24,8 @@ func main() {
|
||||||
app := fiber.New(fiber.Config{
|
app := fiber.New(fiber.Config{
|
||||||
Views: engine,
|
Views: engine,
|
||||||
ViewsLayout: "layouts/main",
|
ViewsLayout: "layouts/main",
|
||||||
|
CaseSensitive: true,
|
||||||
|
StrictRouting: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Use(logger.New())
|
app.Use(logger.New())
|
||||||
|
@ -33,11 +34,6 @@ func main() {
|
||||||
api.Setup(app)
|
api.Setup(app)
|
||||||
data.Setup("sqlite3", "db.sqlite3")
|
data.Setup("sqlite3", "db.sqlite3")
|
||||||
|
|
||||||
app.Static("/", "./public", fiber.Static{
|
|
||||||
Compress: true,
|
|
||||||
CacheDuration: 1 * time.Nanosecond,
|
|
||||||
})
|
|
||||||
|
|
||||||
// this sets up graceful shutdown
|
// this sets up graceful shutdown
|
||||||
go func() {
|
go func() {
|
||||||
if err := app.Listen(":5001"); err != nil {
|
if err := app.Listen(":5001"); err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue