Update main.go
This commit is contained in:
parent
c59574c09c
commit
1ac69e0eb9
44
main.go
44
main.go
@ -8,29 +8,37 @@ import (
|
|||||||
"strings"
|
"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) {
|
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() {
|
func main() {
|
||||||
mux := &MyMux{}
|
http.HandleFunc("/", sayhelloName)
|
||||||
http.ListenAndServe(":9090", mux)
|
http.HandleFunc("/login", login)
|
||||||
err := http.ListenAndServe(":8080", nil) // ustaw port nasłuchiwania
|
err := http.ListenAndServe(":9197", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("ListenAndServe: ", err)
|
log.Fatal("ListenAndServe: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user