Initial
This commit is contained in:
34
app/router/router.go
Normal file
34
app/router/router.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user