Skip to content

Commit 69fb2a4

Browse files
committed
you're doing great
1 parent 2763e98 commit 69fb2a4

File tree

33 files changed

+509
-0
lines changed

33 files changed

+509
-0
lines changed

000_temp/50_disney/01/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
"io"
6+
)
7+
8+
func main() {
9+
http.HandleFunc("/", foo)
10+
http.ListenAndServe(":8080", nil)
11+
}
12+
13+
func foo(w http.ResponseWriter, r *http.Request) {
14+
io.WriteString(w, "Hellooooo!")
15+
}

000_temp/50_disney/02/main.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"html/template"
6+
"net/http"
7+
"encoding/json"
8+
)
9+
10+
var tpl *template.Template
11+
12+
func init() {
13+
tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
14+
}
15+
16+
func main() {
17+
http.HandleFunc("/", index)
18+
http.HandleFunc("/about", about)
19+
http.HandleFunc("/js", js)
20+
http.ListenAndServe(":8080", nil)
21+
}
22+
23+
func index(w http.ResponseWriter, r *http.Request) {
24+
tpl.ExecuteTemplate(w, "index.gohtml", nil)
25+
}
26+
27+
func about(w http.ResponseWriter, r *http.Request) {
28+
tpl.ExecuteTemplate(w, "about.gohtml", nil)
29+
}
30+
31+
func js(w http.ResponseWriter, r *http.Request) {
32+
nj := struct {
33+
First string `json:"first-name"`
34+
Last string `json:"last-name"`
35+
}{
36+
"James",
37+
"Bond",
38+
}
39+
40+
w.Header().Set("Content-Type", "application/json")
41+
42+
err := json.NewEncoder(w).Encode(nj)
43+
if err != nil {
44+
fmt.Println(err)
45+
return
46+
}
47+
//bs, err := json.Marshal(nj)
48+
//if err != nil {
49+
// fmt.Println(err)
50+
// return
51+
//}
52+
//s := string(bs)
53+
//tpl.ExecuteTemplate(w, "js.gohtml", s)
54+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<title>About</title>
8+
</head>
9+
<body>
10+
11+
<h1>All about Disney!</h1>
12+
13+
</body>
14+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<title>Index</title>
8+
</head>
9+
<body>
10+
11+
<h1>Hello Disney!</h1>
12+
13+
</body>
14+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<title>About</title>
8+
</head>
9+
<body>
10+
11+
<h1>{{.}}</h1>
12+
13+
</body>
14+
</html>

000_temp/50_disney/03/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import "fmt"
4+
5+
var x int = 42
6+
7+
func init() {
8+
fmt.Println("in init ", x)
9+
}
10+
11+
func main() {
12+
fmt.Println("in main ", x)
13+
}

000_temp/50_disney/04/main.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"html/template"
5+
"net/http"
6+
)
7+
8+
var tpl *template.Template
9+
10+
func init() {
11+
tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
12+
}
13+
14+
func main() {
15+
http.HandleFunc("/", index)
16+
http.HandleFunc("/about", about)
17+
http.HandleFunc("/dog", dog)
18+
http.ListenAndServe(":8080", nil)
19+
}
20+
21+
func index(w http.ResponseWriter, r *http.Request) {
22+
tpl.ExecuteTemplate(w, "index.gohtml", nil)
23+
}
24+
25+
func about(w http.ResponseWriter, r *http.Request) {
26+
tpl.ExecuteTemplate(w, "about.gohtml", nil)
27+
}
28+
29+
func dog(w http.ResponseWriter, r *http.Request) {
30+
http.ServeFile(w, r, "public/img/toby.jpg")
31+
}
5.04 KB
Loading
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<title>About</title>
8+
</head>
9+
<body>
10+
11+
<h1>All about Disney!</h1>
12+
13+
</body>
14+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<title>Index</title>
8+
</head>
9+
<body>
10+
11+
<h1>Hello Disney!</h1>
12+
<img src="/dog">
13+
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)