initial templ commit

This commit is contained in:
Warwick New 2025-02-21 19:08:14 +00:00
commit 57af2bcb9b
5 changed files with 53 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
fedipod
**_templ.go

5
go.mod Normal file
View file

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

4
go.sum Normal file
View file

@ -0,0 +1,4 @@
github.com/a-h/templ v0.3.833 h1:L/KOk/0VvVTBegtE0fp2RJQiBm7/52Zxv5fqlEHiQUU=
github.com/a-h/templ v0.3.833/go.mod h1:cAu4AiZhtJfBjMY0HASlyzvkrtjnHWPeEsyGK2YYmfk=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=

36
main.go Normal file
View file

@ -0,0 +1,36 @@
package main
import (
"errors"
"fmt"
"github.com/a-h/templ"
"io"
"net/http"
"os"
)
func getRoot(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Got / request\n")
io.WriteString(w, "Website root page\n")
}
func getHello(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Got /hello request\n")
io.WriteString(w, "hello HTTP\n")
}
func main() {
component := root()
mux := http.NewServeMux()
mux.Handle("/", templ.Handler(component))
err := http.ListenAndServe(":3000", mux)
if errors.Is(err, http.ErrServerClosed) {
fmt.Printf("server closed\n")
} else if err != nil {
fmt.Printf("error starting server: %s\n", err)
os.Exit(1)
}
}

6
root.templ Normal file
View file

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