server checks if current device is mobile device, and let browser navigate to specific pages
This commit is contained in:
+8
-1
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/mssola/user_agent"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/mayswind/lab/pkg/api"
|
||||
@@ -81,7 +82,13 @@ func startWebServer(c *cli.Context) error {
|
||||
router.NoMethod(bindApi(api.Default.MethodNotAllowed))
|
||||
|
||||
router.GET("/", func(c *gin.Context) {
|
||||
c.Redirect(http.StatusMovedPermanently, "/mobile/")
|
||||
ua := user_agent.New(c.GetHeader("User-Agent"))
|
||||
|
||||
if ua.Mobile() {
|
||||
c.Redirect(http.StatusMovedPermanently, "/mobile/")
|
||||
} else {
|
||||
c.Redirect(http.StatusMovedPermanently, "/desktop/")
|
||||
}
|
||||
})
|
||||
|
||||
router.StaticFile("robots.txt", filepath.Join(config.StaticRootPath, "robots.txt"))
|
||||
|
||||
@@ -10,6 +10,7 @@ require (
|
||||
github.com/go-sql-driver/mysql v1.5.0
|
||||
github.com/lib/pq v1.8.0
|
||||
github.com/mattn/go-sqlite3 v1.14.4
|
||||
github.com/mssola/user_agent v0.5.2
|
||||
github.com/pquerna/otp v1.3.0
|
||||
github.com/sirupsen/logrus v1.7.0
|
||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||
|
||||
@@ -61,6 +61,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/mssola/user_agent v0.5.2 h1:CZkTUahjL1+OcZ5zv3kZr8QiJ8jy2H08vZIEkBeRbxo=
|
||||
github.com/mssola/user_agent v0.5.2/go.mod h1:TTPno8LPY3wAIEKRpAtkdMT0f8SE24pLRGPahjCH4uw=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
|
||||
+6
-2
@@ -1,7 +1,11 @@
|
||||
<template>
|
||||
<div>Not Implemented</div>
|
||||
<div></div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {}
|
||||
export default {
|
||||
created() {
|
||||
location.href = '../mobile/'
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -69,6 +69,12 @@ const licenses = [
|
||||
url: 'https://github.com/mattn/go-sqlite3',
|
||||
licenseUrl: 'https://github.com/mattn/go-sqlite3/blob/master/LICENSE'
|
||||
},
|
||||
{
|
||||
name: 'UserAgent',
|
||||
copyright: 'Copyright (c) 2012-2020 Miquel Sabaté Solà',
|
||||
url: 'https://github.com/mssola/user_agent',
|
||||
licenseUrl: 'https://github.com/mssola/user_agent/blob/master/LICENSE'
|
||||
},
|
||||
{
|
||||
name: 'Go Cryptography',
|
||||
copyright: 'Copyright (c) 2009 The Go Authors. All rights reserved.',
|
||||
|
||||
Reference in New Issue
Block a user