summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2024-02-11 23:45:56 +0100
committerRené 'Necoro' Neumann <necoro@necoro.eu>2024-02-11 23:45:56 +0100
commit934df3f098c33bcbb1493a420833817b80518020 (patch)
treef2fa5d6356bc32b84c6f19377ca106c627f4132b /main.go
parent09cb0762553494f2e31f4a7dc60c0c4ba09e91a1 (diff)
downloadgosten-934df3f098c33bcbb1493a420833817b80518020.tar.gz
gosten-934df3f098c33bcbb1493a420833817b80518020.tar.bz2
gosten-934df3f098c33bcbb1493a420833817b80518020.zip
Include form handling
Diffstat (limited to 'main.go')
-rw-r--r--main.go29
1 files changed, 26 insertions, 3 deletions
diff --git a/main.go b/main.go
index dd735a1..10ec34a 100644
--- a/main.go
+++ b/main.go
@@ -1,7 +1,6 @@
package main
import (
- "context"
"database/sql"
"flag"
"log"
@@ -9,6 +8,8 @@ import (
"net/http"
"strconv"
+ "github.com/gorilla/schema"
+
"gosten/model"
"gosten/templ"
@@ -27,6 +28,9 @@ func init() {
flag.Uint64Var(&port, "p", 8080, "port to listen on")
}
+var Q *model.Queries
+var s *schema.Decoder
+
func main() {
flag.Parse()
@@ -35,8 +39,8 @@ func main() {
log.Fatal(err)
}
- queries := model.New(db)
- _, err = queries.GetUsers(context.Background())
+ Q = model.New(db)
+ s = schema.NewDecoder()
r := chi.NewRouter()
@@ -51,6 +55,25 @@ func main() {
templ.Lookup("index").Execute(w, nil)
})
+ r.Route("/login", func(r chi.Router) {
+
+ type User struct {
+ Name string `form:"options=required"`
+ Password string `form:"type=password;options=required"`
+ }
+
+ r.Get("/", func(w http.ResponseWriter, _ *http.Request) {
+ templ.Lookup("login").Execute(w, User{})
+ })
+
+ r.Post("/", func(w http.ResponseWriter, r *http.Request) {
+ u := User{}
+ r.ParseForm()
+ s.Decode(&u, r.PostForm)
+ templ.Lookup("login2").Execute(w, u)
+ })
+ })
+
address := net.JoinHostPort(host, strconv.FormatUint(port, 10))
log.Fatal(http.ListenAndServe(address, r))
}