mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 06:57:35 +08:00
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"))
|
||||
|
||||
Reference in New Issue
Block a user