-
Notifications
You must be signed in to change notification settings - Fork 20
/
app.go
28 lines (24 loc) · 969 Bytes
/
app.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
package main
import (
"fmt"
"log"
"net/http"
"github.com/Shaked/gomobiledetect"
)
func handler(w http.ResponseWriter, r *http.Request) {
detect := mobiledetect.NewMobileDetect(r, nil)
requestValue := r.URL.Query().Get("r")
fmt.Fprintln(w, "isMobile?", detect.IsMobile())
fmt.Fprintln(w, "isTablet?", detect.IsTablet())
fmt.Fprintln(w, "is(request)?", requestValue, " ", detect.Is(requestValue))
fmt.Fprintln(w, "isKey(request)?", requestValue, " ", detect.IsKey(mobiledetect.IPHONE))
fmt.Fprintln(w, "Version: ", detect.Version(requestValue))
fmt.Fprintln(w, "VersionKey: ", detect.Version(mobiledetect.PROP_IPHONE))
fmt.Fprintln(w, "VersionFloat: ", detect.Version(requestValue))
fmt.Fprintln(w, "VersionFloatKey: ", detect.Version(mobiledetect.PROP_IPHONE))
}
func main() {
log.Println("Starting local server http://localhost:10001/check (cmd+click to open from terminal)")
http.HandleFunc("/check", handler)
http.ListenAndServe(":10001", nil)
}