diff options
author | René Neumann <necoro@necoro.eu> | 2024-02-10 23:24:37 +0100 |
---|---|---|
committer | René Neumann <necoro@necoro.eu> | 2024-02-10 23:24:37 +0100 |
commit | 91d14e414fc9c451879e834d7866ad765084a836 (patch) | |
tree | 1fa8a757feda3d2c721aa9382f32a69109626ea7 /main.go | |
parent | 2d90d4e00a111ddf22440334d99323fe0d8216be (diff) | |
download | gosten-91d14e414fc9c451879e834d7866ad765084a836.tar.gz gosten-91d14e414fc9c451879e834d7866ad765084a836.tar.bz2 gosten-91d14e414fc9c451879e834d7866ad765084a836.zip |
Add templating
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 24 |
1 files changed, 7 insertions, 17 deletions
@@ -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)) |