Got templ template based htmx project rendering

This commit is contained in:
Warwick New 2025-03-12 17:56:04 +00:00
parent 57af2bcb9b
commit bb3b9c3a7c
5 changed files with 23 additions and 8 deletions

2
go.mod
View file

@ -1,5 +1,5 @@
module fedipod module fedipod
go 1.23.6 go 1.23.7
require github.com/a-h/templ v0.3.833 require github.com/a-h/templ v0.3.833

View file

@ -2,6 +2,7 @@ package main
import ( import (
"errors" "errors"
"fedipod/views"
"fmt" "fmt"
"github.com/a-h/templ" "github.com/a-h/templ"
"io" "io"
@ -21,11 +22,12 @@ func getHello(w http.ResponseWriter, r *http.Request) {
func main() { func main() {
component := root() component := views.Index()
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle("/", templ.Handler(component)) mux.Handle("/", templ.Handler(component))
fmt.Printf("Running server\n")
err := http.ListenAndServe(":3000", mux) err := http.ListenAndServe(":3000", mux)
if errors.Is(err, http.ErrServerClosed) { if errors.Is(err, http.ErrServerClosed) {
fmt.Printf("server closed\n") fmt.Printf("server closed\n")

View file

@ -1,6 +0,0 @@
package main
templ root() {
<div>Hello HTTP</div>
}

View 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
View file

@ -0,0 +1,10 @@
package views
import "fedipod/views/components"
templ Index() {
<!DOCTYPE html>
<html lang="en">
@components.Header()
</html>
}