Almost working

This commit is contained in:
Eden Kirin
2024-01-21 00:17:49 +01:00
parent 960c22a8c8
commit 9d76a8dc22
6 changed files with 151 additions and 53 deletions

View File

@ -1,5 +1,15 @@
package handlers
import "github.com/gin-gonic/gin"
import (
"net/http"
func Home(c *gin.Context) {}
"templ-tests/app/templates"
"github.com/gin-gonic/gin"
)
func Home(c *gin.Context) {
content := templates.Home()
c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(content))
}

View File

@ -9,7 +9,7 @@ import (
)
const (
APPHOST string = "0.0.0.0"
APPHOST string = "127.0.0.1"
APPPORT int = 8000
STATIC_PATH string = "./static"
)
@ -27,7 +27,7 @@ func initRouter() *gin.Engine {
func Serve() {
serverAddr := fmt.Sprintf("%s:%d", APPHOST, APPPORT)
fmt.Printf("Starting serving on %s\n", serverAddr)
fmt.Printf("Starting serving on http://%s\n", serverAddr)
router := initRouter()
router.Run(serverAddr)

7
app/templates/home.templ Normal file
View File

@ -0,0 +1,7 @@
package templates
templ Home(name string) {
@baseLayout() {
<div>Hello, { name }</div>
}
}

View File

@ -0,0 +1,15 @@
package templates
templ baseLayout() {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Document</title>
</head>
<body>
{ children... }
</body>
</html>
}