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
import "fmt"
import (
"fmt"
"html/template"
"log"
"net/http"
"strings"
)
type person struct {
name string
age int
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, ""))
}
func Older(p1, p2 person) (person, int) {
if p1.age > p2.age {
return p1, p1.age - p2.age
}
return p2, p2.age - p1.age
fmt.Fprintf(w, "Cześć!") // wyślij dane na strone
}
func main() {
var tom person
tom.name, tom.age = "Tom", 18
bob := person{age: 25, name: "Bob"}
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)
http.HandleFunc("/", sayhelloName) // ustaw router
err := http.ListenAndServe(":8080", nil) // ustaw port nasłuchiwania
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}