From f6e6b277400a03c9ceaa0231e2d3e5f794fa047f Mon Sep 17 00:00:00 2001 From: bonfy Date: Mon, 10 Sep 2018 14:12:16 +0800 Subject: [PATCH] 04-Web-Form add login form MethodPost handle --- controller/home.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/controller/home.go b/controller/home.go index 4f4a5a3..5bea362 100644 --- a/controller/home.go +++ b/controller/home.go @@ -1,6 +1,7 @@ package controller import ( + "fmt" "net/http" "github.com/bonfy/go-mega-code/vm" @@ -24,5 +25,13 @@ func loginHandler(w http.ResponseWriter, r *http.Request) { tpName := "login.html" vop := vm.LoginViewModelOp{} v := vop.GetVM() - templates[tpName].Execute(w, &v) + if r.Method == http.MethodGet { + templates[tpName].Execute(w, &v) + } + if r.Method == http.MethodPost { + r.ParseForm() + username := r.Form.Get("username") + password := r.Form.Get("password") + fmt.Fprintf(w, "Username:%s Password:%s", username, password) + } }