Update main.go
This commit is contained in:
parent
aafe9dc9b5
commit
76f30faf5c
45
main.go
45
main.go
@ -1,31 +1,30 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
type person struct {
|
func sayhelloName(w http.ResponseWriter, r *http.Request) {
|
||||||
name string
|
r.ParseForm() // analizuj argumenty, musisz to sam wywołać
|
||||||
age int
|
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
|
||||||
func Older(p1, p2 person) (person, int) {
|
|
||||||
if p1.age > p2.age {
|
|
||||||
return p1, p1.age - p2.age
|
|
||||||
}
|
|
||||||
return p2, p2.age - p1.age
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var tom person
|
http.HandleFunc("/", sayhelloName) // ustaw router
|
||||||
|
err := http.ListenAndServe(":8080", nil) // ustaw port nasłuchiwania
|
||||||
tom.name, tom.age = "Tom", 18
|
if err != nil {
|
||||||
bob := person{age: 25, name: "Bob"}
|
log.Fatal("ListenAndServe: ", err)
|
||||||
paul := person{"Paul", 43}
|
}
|
||||||
|
|
||||||
tb_Older, tb_diff := Older(tom, bob)
|
|
||||||
tp_Older, tp_diff := Older(tom, paul)
|
|
||||||
bp_Older, bp_diff := Older(bob, paul)
|
|
||||||
|
|
||||||
fmt.Printf("Of %s and %s, %s is older by %d years\n", tom.name, bob.name, tb_Older.name, tb_diff)
|
|
||||||
fmt.Printf("Of %s and %s, %s is older by %d years\n", tom.name, paul.name, tp_Older.name, tp_diff)
|
|
||||||
fmt.Printf("Of %s and %s, %s is older by %d years\n", bob.name, paul.name, bp_Older.name, bp_diff)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user