initial templ commit
This commit is contained in:
commit
57af2bcb9b
5 changed files with 53 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fedipod
|
||||
**_templ.go
|
||||
5
go.mod
Normal file
5
go.mod
Normal 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
4
go.sum
Normal 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
36
main.go
Normal 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
6
root.templ
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package main
|
||||
|
||||
templ root() {
|
||||
<div>Hello HTTP</div>
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue