This commit is contained in:
Eden Kirin
2024-01-20 23:46:36 +01:00
commit 960c22a8c8
10 changed files with 319 additions and 0 deletions

34
app/router/router.go Normal file
View File

@ -0,0 +1,34 @@
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)
}