Almost working
This commit is contained in:
@ -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))
|
||||
}
|
||||
|
||||
@ -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
7
app/templates/home.templ
Normal file
@ -0,0 +1,7 @@
|
||||
package templates
|
||||
|
||||
templ Home(name string) {
|
||||
@baseLayout() {
|
||||
<div>Hello, { name }</div>
|
||||
}
|
||||
}
|
||||
15
app/templates/layout.templ
Normal file
15
app/templates/layout.templ
Normal 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>
|
||||
}
|
||||
Reference in New Issue
Block a user