Files
go-htmx-templ/app/router/router.go
2024-01-21 18:09:02 +01:00

44 lines
946 B
Go

package router
import (
"fmt"
"templ-tests/app/handlers"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
)
const (
APPHOST string = "127.0.0.1"
APPPORT int = 8000
STATIC_PATH string = "./static"
)
func initRouter() *gin.Engine {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
router.Use(corsMiddleware())
router.GET("/", handlers.Home)
router.GET("/about", handlers.About)
interactiveRouter := router.Group("/interactive")
{
interactiveRouter.GET("", handlers.Interactive)
interactiveRouter.GET("/swap-content", handlers.InteractiveSwapContent)
interactiveRouter.GET("/filter-cat-breeds", handlers.FilterCatBreeds)
}
router.Use(static.Serve("/static", static.LocalFile(STATIC_PATH, false)))
return router
}
func Serve() {
serverAddr := fmt.Sprintf("%s:%d", APPHOST, APPPORT)
fmt.Printf("Starting serving on http://%s\n", serverAddr)
router := initRouter()
router.Run(serverAddr)
}