summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRené Neumann <necoro@necoro.eu>2024-02-10 23:24:37 +0100
committerRené Neumann <necoro@necoro.eu>2024-02-10 23:24:37 +0100
commit91d14e414fc9c451879e834d7866ad765084a836 (patch)
tree1fa8a757feda3d2c721aa9382f32a69109626ea7 /main.go
parent2d90d4e00a111ddf22440334d99323fe0d8216be (diff)
downloadgosten-91d14e414fc9c451879e834d7866ad765084a836.tar.gz
gosten-91d14e414fc9c451879e834d7866ad765084a836.tar.bz2
gosten-91d14e414fc9c451879e834d7866ad765084a836.zip
Add templating
Diffstat (limited to 'main.go')
-rw-r--r--main.go24
1 files changed, 7 insertions, 17 deletions
diff --git a/main.go b/main.go
index 92ae59e..b8d2436 100644
--- a/main.go
+++ b/main.go
@@ -4,12 +4,13 @@ import (
"context"
"database/sql"
"flag"
- "fmt"
- "gosten/model"
"log"
"net"
"net/http"
"strconv"
+
+ "gosten/model"
+ "gosten/templ"
)
// flags
@@ -32,22 +33,11 @@ func main() {
}
queries := model.New(db)
+ _, err = queries.GetUsers(context.Background())
- helloHandler := func(w http.ResponseWriter, req *http.Request) {
- fmt.Fprintln(w, "Hello, world!")
- fmt.Fprintf(w, "Running on %s:%d\n", host, port)
-
- users, err := queries.GetUsers(context.Background())
- if err != nil {
- log.Fatal(err)
- }
-
- fmt.Fprintln(w, "\nUSERS")
- for _, u := range users {
- fmt.Fprintln(w, u.Name)
- }
- }
- http.HandleFunc("/", helloHandler)
+ http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
+ templ.Lookup("index").Execute(w, nil)
+ })
address := net.JoinHostPort(host, strconv.FormatUint(port, 10))
log.Fatal(http.ListenAndServe(address, nil))