Got templ template based htmx project rendering
This commit is contained in:
parent
57af2bcb9b
commit
bb3b9c3a7c
5 changed files with 23 additions and 8 deletions
2
go.mod
2
go.mod
|
|
@ -1,5 +1,5 @@
|
|||
module fedipod
|
||||
|
||||
go 1.23.6
|
||||
go 1.23.7
|
||||
|
||||
require github.com/a-h/templ v0.3.833
|
||||
|
|
|
|||
4
main.go
4
main.go
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fedipod/views"
|
||||
"fmt"
|
||||
"github.com/a-h/templ"
|
||||
"io"
|
||||
|
|
@ -21,11 +22,12 @@ func getHello(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
func main() {
|
||||
|
||||
component := root()
|
||||
component := views.Index()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/", templ.Handler(component))
|
||||
|
||||
fmt.Printf("Running server\n")
|
||||
err := http.ListenAndServe(":3000", mux)
|
||||
if errors.Is(err, http.ErrServerClosed) {
|
||||
fmt.Printf("server closed\n")
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
package main
|
||||
|
||||
templ root() {
|
||||
<div>Hello HTTP</div>
|
||||
}
|
||||
|
||||
9
views/components/header.templ
Normal file
9
views/components/header.templ
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
package components
|
||||
|
||||
templ Header() {
|
||||
<head>
|
||||
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>fedipod</title>
|
||||
</head>
|
||||
}
|
||||
10
views/index.templ
Normal file
10
views/index.templ
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package views
|
||||
|
||||
import "fedipod/views/components"
|
||||
|
||||
templ Index() {
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@components.Header()
|
||||
</html>
|
||||
}
|
||||
Loading…
Reference in a new issue