Skip to content

Commit 3fbe282

Browse files
committed
you're doing great
1 parent 13593af commit 3fbe282

File tree

7 files changed

+137
-0
lines changed

7 files changed

+137
-0
lines changed

000_temp/64-HANDLER/main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
"io"
6+
)
7+
8+
9+
type hotdog int
10+
11+
// func receiver identifier(params) return(s) {}
12+
func (h hotdog) ServeHTTP(w http.ResponseWriter, r *http.Request) {
13+
io.WriteString(w, "WASSSSSUP!!!!!")
14+
}
15+
16+
func main() {
17+
var d hotdog
18+
http.ListenAndServe(":8080", d)
19+
}
20+
21+
/*
22+
23+
type Handler
24+
type Handler interface {
25+
ServeHTTP(ResponseWriter, *Request)
26+
}
27+
28+
*/

000_temp/65-DEFAULT-SERVE-MUX/main.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
"log"
6+
"fmt"
7+
"html"
8+
"io"
9+
)
10+
11+
12+
type hotdog int
13+
14+
func (h hotdog) ServeHTTP(w http.ResponseWriter, r *http.Request) {
15+
io.WriteString(w, "hello from baz")
16+
}
17+
18+
func main() {
19+
20+
var bazhandler hotdog
21+
22+
http.Handle("/baz", bazhandler)
23+
24+
http.HandleFunc("/foo", fooHandler)
25+
26+
http.HandleFunc("/bar/", func(w http.ResponseWriter, r *http.Request) {
27+
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
28+
})
29+
30+
31+
log.Fatal(http.ListenAndServe(":8080", nil))
32+
33+
}
34+
35+
func fooHandler(w http.ResponseWriter, r *http.Request) {
36+
io.WriteString(w, "hello from foo")
37+
}
38+
39+
40+
/*
41+
42+
type Handler
43+
type Handler interface {
44+
ServeHTTP(ResponseWriter, *Request)
45+
}
46+
47+
*/

000_temp/66-HANDLEFUNC/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
"io"
6+
"fmt"
7+
)
8+
9+
func main() {
10+
http.HandleFunc("/", home)
11+
http.HandleFunc("/about", about)
12+
http.HandleFunc("/contact", contact)
13+
14+
http.ListenAndServe(":8080", nil)
15+
}
16+
17+
func home(w http.ResponseWriter, r *http.Request) {
18+
io.WriteString(w, "hello from home")
19+
}
20+
21+
func about (w http.ResponseWriter, r *http.Request) {
22+
io.WriteString(w, "wassup from about")
23+
}
24+
25+
func contact (w http.ResponseWriter, r * http.Request) {
26+
fmt.Fprint(w, "get in touch with us, yo, here at contact")
27+
}

000_temp/67-KABOOM-BOOOYAH/main.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
"html/template"
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("/", home)
16+
http.HandleFunc("/about", about)
17+
http.HandleFunc("/contact", contact)
18+
19+
http.ListenAndServe(":8080", nil)
20+
}
21+
22+
func home(w http.ResponseWriter, r *http.Request) {
23+
tpl.ExecuteTemplate(w, "default.gohtml", nil)
24+
}
25+
26+
func about (w http.ResponseWriter, r *http.Request) {
27+
tpl.ExecuteTemplate(w, "about.gohtml", nil)
28+
}
29+
30+
func contact (w http.ResponseWriter, r * http.Request) {
31+
tpl.ExecuteTemplate(w, "contact.gohtml", nil)
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello from about
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello from contact
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello from default

0 commit comments

Comments
 (0)