-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
35 lines (28 loc) · 844 Bytes
/
main.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
package main
import (
"fmt"
"log"
"net/http"
"github.com/houseme/mobiledetect"
)
// Handler .
type Handler struct{}
// Mobile .
func (h *Handler) Mobile(w http.ResponseWriter, r *http.Request, m *mobiledetect.MobileDetect) {
fmt.Fprint(w, "Hello, this is mobile")
}
// Tablet .
func (h *Handler) Tablet(w http.ResponseWriter, r *http.Request, m *mobiledetect.MobileDetect) {
fmt.Fprint(w, "Hello, this is tablet")
}
// Desktop .
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)
}