-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
49 lines (40 loc) · 1.65 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"log"
"net/http"
"github.com/houseme/mobiledetect"
)
func handler(w http.ResponseWriter, r *http.Request) {
detect := mobiledetect.New(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.PropIphone))
fmt.Fprintln(w, "VersionFloat: ", detect.Version(requestValue))
fmt.Fprintln(w, "VersionFloatKey: ", detect.Version(mobiledetect.PropIphone))
// Any mobile device (phones or tablets).
fmt.Println(detect.IsMobile())
// Any tablet device.
fmt.Println(detect.IsTablet())
// Exclude tablets.
fmt.Println(detect.IsMobile() && !detect.IsTablet())
// Check for a specific platform with the help of the magic methods:
fmt.Println(detect.Is("iPhone"))
// Alternative method is() for checking specific properties.
// WARNING: this method is in BETA, some keyword properties will change in the future.
fmt.Println(detect.Is("Chrome"))
fmt.Println(detect.Is("iOS"))
fmt.Println(detect.Is("UC Browser"))
// Get the version() of components.
// WARNING: this method is in BETA, some keyword properties will change in the future.
fmt.Println(detect.VersionFloat("Android"))
}
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)
}