diff options
Diffstat (limited to '')
-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)) |