-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6
52 lines (43 loc) · 780 Bytes
/
6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"net/http"
)
type worker struct {
pers human
exp int
}
type human struct {
name string
age int
}
type hr struct {
wor *worker
country string
field string
}
type coder struct {
wor worker
primaryTech string
secondaryTech string
}
func handler(w http.ResponseWriter, r *http.Request) {
str := ""
query := r.URL.Query()
str = query.Get("name")
fmt.Println(str)
if str == "" {
str = r.PostFormValue("name")
}
x := fmt.Sprintln(m[str])
fmt.Fprintf(w, x)
}
var m map[string]worker
func main() {
m = make(map[string]worker)
m["1"] = worker{human{"Mike", 30}, 8}
m["2"] = worker{human{"Jack", 35}, 10}
http.HandleFunc("/", handler)
http.HandleFunc("/greet", handler)
http.ListenAndServe(":8000", nil)
}