-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_test.go
66 lines (57 loc) · 1.42 KB
/
handler_test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package golang_web
import (
"fmt"
"net/http"
"testing"
)
func TestHanlder(t *testing.T) {
var handler http.HandlerFunc = func(writer http.ResponseWriter, request *http.Request) {
// logic nya
fmt.Fprint(writer, "Hello Sandi")
}
server := http.Server{
Addr: "localhost:8080",
Handler: handler,
}
err := server.ListenAndServe()
if err != nil {
panic(err)
}
}
func TestServeMux(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer, "Hello Sandi")
})
mux.HandleFunc("/hai", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer, "Hai")
})
mux.HandleFunc("/images/", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer, "Images")
})
mux.HandleFunc("/images/thumbnails/", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer, "Images Thumbnail")
})
server := http.Server{
Addr: "localhost:8080",
Handler: mux,
}
err := server.ListenAndServe()
if err != nil {
panic(err)
}
}
func TestRequest(t *testing.T) { // Get / isi/isi/
var handler http.HandlerFunc = func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprintln(writer, request.Method)
fmt.Fprintln(writer, request.RequestURI)
}
server := http.Server{
Addr: "localhost:8080",
Handler: handler,
}
err := server.ListenAndServe()
if err != nil {
panic(err)
}
}