Update main.go
This commit is contained in:
parent
17ab2fea32
commit
3ae8d75aa5
30
main.go
30
main.go
@ -8,21 +8,27 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func sayhelloName(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm() // analizuj argumenty, musisz to sam wywołać
|
||||
fmt.Println(r.Form) // drukuj informacje formularzy po stronie serwera
|
||||
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, "Cześć!") // wyślij dane na strone
|
||||
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!")
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
//==============================================================================
|
||||
func main() {
|
||||
http.HandleFunc("/", sayhelloName) // ustaw router
|
||||
mux := &MyMux{}
|
||||
http.ListenAndServe(":9090", mux)
|
||||
err := http.ListenAndServe(":8080", nil) // ustaw port nasłuchiwania
|
||||
if err != nil {
|
||||
log.Fatal("ListenAndServe: ", err)
|
||||
|
Loading…
Reference in New Issue
Block a user