-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (33 loc) · 849 Bytes
/
main.go
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
package main
import "net/http"
import "fmt"
import "html/template"
type Info struct {
Affiliation string
Address string
}
type Person struct {
Name string
Gender string
Hobbies []string
Info Info
}
func (t Info) GetAffiliationDetailInfo() string {
return "have 31 divisions"
}
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
var person = Person{
Name: "Bruce Wayne",
Gender: "male",
Hobbies: []string{"Reading Books", "Traveling", "Buying things"},
Info: Info{"Wayne Enterprises", "Gotham City"},
}
var tmpl = template.Must(template.ParseFiles("view.html"))
if err := tmpl.Execute(w, person); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
fmt.Println("server started at localhost:9000")
http.ListenAndServe(":9000", nil)
}