Skip to content

floresj/go-contrib-mobile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

go-contrib-mobile

wercker status

A middleware for gin-gonic that determines whether a user is using a mobile, tablet or normal device. This middleware was inspired by the spring-mobile project by the good folks from the spring framework.

Examples

package main

import (
    "fmt"
    "net/http"
    "github.com/gin-gonic/gin"
    "github.com/floresj/go-contrib-mobile"
)


func main() {
    r := gin.Default()
    fmt.Println("Main!")
  // Set up Mobile Resolver
    r.Use(mobile.Resolver())

    r.GET("/", func(c *gin.Context){
      // Get handle to Device
        d := mobile.GetDevice(c)

        switch {
        // Hey I'm a desktop!... or laptop but not a mobile or tablet!
        case d.Normal():
            c.JSON(http.StatusOK, "Hello I'm a normal device")
        // Hey I'm a mobile device!
        case d.Mobile():
            c.JSON(http.StatusOK, "Hello I'm a mobile device")
        // Woa I'm a tablet!
        case d.Tablet():
            c.JSON(http.StatusOK, "Hello I'm a tablet device")
        }
    })

    r.Run(":9000")
}

About

Device type resolver for gin-gonic. Enables server-side endpoints to determine if a user is using a mobile or tablet device.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages