Files
go-htmx-templ/app/router/router.go
Eden Kirin 960c22a8c8 Initial
2024-01-20 23:46:36 +01:00

35 lines
644 B
Go

package router
import (
"fmt"
"templ-tests/app/handlers"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
)
const (
APPHOST string = "0.0.0.0"
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.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 %s\n", serverAddr)
router := initRouter()
router.Run(serverAddr)
}