Update main.go

This commit is contained in:
s441433 2018-12-10 15:52:29 +01:00
parent aafe9dc9b5
commit 76f30faf5c

45
main.go
View File

@ -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)
func Older(p1, p2 person) (person, int) { fmt.Println(r.Form["url_long"])
if p1.age > p2.age { for k, v := range r.Form {
return p1, p1.age - p2.age fmt.Println("key:", k)
fmt.Println("val:", strings.Join(v, ""))
} }
return p2, p2.age - p1.age fmt.Fprintf(w, "Cześć!") // wyślij dane na strone
} }
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)
} }