-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathapp_handler.go
More file actions
38 lines (33 loc) · 805 Bytes
/
app_handler.go
File metadata and controls
38 lines (33 loc) · 805 Bytes
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
package main
import (
"fmt"
"log"
"net/http"
"github.com/Shaked/gomobiledetect"
)
type Handler struct{}
func (h *Handler) Mobile(w http.ResponseWriter,
r *http.Request,
m *mobiledetect.MobileDetect,
) {
fmt.Fprint(w, "Hello, this is mobile")
}
func (h *Handler) Tablet(w http.ResponseWriter,
r *http.Request,
m *mobiledetect.MobileDetect,
) {
fmt.Fprint(w, "Hello, this is tablet")
}
func (h *Handler) Desktop(w http.ResponseWriter,
r *http.Request,
m *mobiledetect.MobileDetect,
) {
fmt.Fprint(w, "Hello, this is desktop", m.MobileGrade())
}
func main() {
log.Println("Starting local server http://localhost:10001/check (cmd+click to open from terminal)")
mux := http.NewServeMux()
h := &Handler{}
mux.Handle("/", mobiledetect.Handler(h, nil))
http.ListenAndServe(":10001", mux)
}