-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
117 lines (104 loc) · 2.59 KB
/
handler.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"fmt"
"log"
"net/http"
"github.com/Shaked/godevicedetect"
"github.com/Shaked/godevicedetect/platform"
)
type Handler struct{}
func (h *Handler) Mobile(w http.ResponseWriter,
r *http.Request,
d *platform.DeviceMobile,
) {
p := d.Platform()
if nil != p {
fmt.Fprint(w, "Hello, this is: ", d.Type(), d.Platform().Name(), d.Platform().Version())
} else {
fmt.Fprint(w, "Hello, this is: ", d.Type())
}
}
func (h *Handler) Tablet(w http.ResponseWriter,
r *http.Request,
d *platform.DeviceTablet,
) {
p := d.Platform()
if nil != p {
fmt.Fprint(w, "Hello, this is: ", d.Type(), d.Platform().Name(), d.Platform().Version())
} else {
fmt.Fprint(w, "Hello, this is: ", d.Type())
}
}
func (h *Handler) Desktop(w http.ResponseWriter,
r *http.Request,
d *platform.DeviceDesktop,
) {
p := d.Platform()
if nil != p {
fmt.Fprint(w, "Hello, this is: ", d.Type(), d.Platform().Name(), d.Platform().Version())
} else {
fmt.Fprint(w, "Hello, this is: ", d.Type())
}
}
func (h *Handler) Bot(w http.ResponseWriter,
r *http.Request,
d *platform.DeviceBot,
) {
p := d.Platform()
if nil != p {
fmt.Fprint(w, "Hello, this is: ", d.Type(), d.Platform().Name(), d.Platform().Version())
} else {
fmt.Fprint(w, "Hello, this is: ", d.Type())
}
}
func (h *Handler) Glass(w http.ResponseWriter,
r *http.Request,
d *platform.DeviceGlass,
) {
p := d.Platform()
if nil != p {
fmt.Fprint(w, "Hello, this is: ", d.Type(), d.Platform().Name(), d.Platform().Version())
} else {
fmt.Fprint(w, "Hello, this is: ", d.Type())
}
}
func (h *Handler) Watch(w http.ResponseWriter,
r *http.Request,
d *platform.DeviceWatch,
) {
p := d.Platform()
if nil != p {
fmt.Fprint(w, "Hello, this is: ", d.Type(), d.Platform().Name(), d.Platform().Version())
} else {
fmt.Fprint(w, "Hello, this is: ", d.Type())
}
}
func (h *Handler) Tv(w http.ResponseWriter,
r *http.Request,
d *platform.DeviceTv,
) {
p := d.Platform()
if nil != p {
fmt.Fprint(w, "Hello, this is: ", d.Type(), d.Platform().Name(), d.Platform().Version())
} else {
fmt.Fprint(w, "Hello, this is: ", d.Type())
}
}
func (h *Handler) Unknown(w http.ResponseWriter,
r *http.Request,
d *platform.DeviceUnknown,
) {
p := d.Platform()
if nil != p {
fmt.Fprint(w, "Hello, this is: ", d.Type(), d.Platform().Name(), d.Platform().Version())
} else {
fmt.Fprint(w, "Hello, this is: ", d.Type())
}
}
func main() {
log.Println("Starting local server http://localhost:8000/ (cmd+click to open from terminal)")
h := &Handler{}
mux := http.NewServeMux()
mux.Handle("/", godevicedetect.Handler(h, nil))
http.ListenAndServe(":8000", mux)
}