From 1ac69e0eb94191e1a5394de009223a600159d9f8 Mon Sep 17 00:00:00 2001 From: s441433 Date: Mon, 10 Dec 2018 18:00:33 +0100 Subject: [PATCH] Update main.go --- main.go | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index 4244d72..2dd05bf 100644 --- a/main.go +++ b/main.go @@ -8,29 +8,37 @@ import ( "strings" ) -type MyMux struct { -} - -func (p *MyMux) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/" { - sayhelloName(w, r) - return - } - http.NotFound(w, r) - return -} - func sayhelloName(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hello myroute!") + r.ParseForm() + fmt.Println(r.Form) + fmt.Println("path", r.URL.Path) + fmt.Println("scheme", r.URL.Scheme) + fmt.Println(r.Form["url_long"]) + for k, v := range r.Form { + fmt.Println("key:", k) + fmt.Println("val:", strings.Join(v, "")) + } + fmt.Fprintf(w, "Hello astaxie!") +} + +func login(w http.ResponseWriter, r *http.Request) { + fmt.Println("method:", r.Method) + if r.Method == "GET" { + t, _ := template.ParseFiles("login.gtpl") + t.Execute(w, nil) + } else { + r.ParseForm() + fmt.Println("username:", r.Form["username"]) + fmt.Println("password:", r.Form["password"]) + } } -//============================================================================== -//============================================================================== func main() { - mux := &MyMux{} - http.ListenAndServe(":9090", mux) - err := http.ListenAndServe(":8080", nil) // ustaw port nasłuchiwania + http.HandleFunc("/", sayhelloName) + http.HandleFunc("/login", login) + err := http.ListenAndServe(":9197", nil) if err != nil { log.Fatal("ListenAndServe: ", err) } + }