Gin middlewares providing Google App Engine integrations.
Only checked are provided currently.
- GAE Context - Set a variable on the Gin context, containing the GAE Context.
- GAE User
- Set a variable on the Gin context, containing the GAE User, logged in using the standard user authentication.
- Set a variable on the Gin context, containing the GAE User, logged in using OAuth.
- GAE Authentication - Fail a request with a 401 if user is not authenticated.
You always have to include GAE Context, as all the others depend on that.
package app
import (
"appengine"
"github.com/frankbille/gingae"
"github.com/gin-gonic/gin"
)
func init() {
r := gin.New()
r.Use(gingae.GaeContext())
r.GET("/posts", func(c *gin.Context) {
gaeCtx := c.Get(gingae.Context).(appengine.Context)
// Do stuff which requires the GAE Context
})
http.Handle("/", r)
}
package app
import (
"appengine/user"
"github.com/frankbille/gingae"
"github.com/gin-gonic/gin"
)
func init() {
r := gin.New()
// You always have to include GaeContext, as all the other middlewares depend on it.
r.Use(gingae.GaeContext())
r.Use(gingae.GaeUser())
r.GET("/admin", func(c *gin.Context) {
gaeUser := c.Get(gingae.User).(user.User)
// Do stuff with the GAE User
})
http.Handle("/", r)
}
package app
import (
"appengine/user"
"github.com/frankbille/gingae"
"github.com/gin-gonic/gin"
)
func init() {
r := gin.New()
// You always have to include GaeContext, as all the other middlewares depend on it.
r.Use(gingae.GaeContext())
r.Use(gingae.GaeUserOAuth("profile"))
r.GET("/admin", func(c *gin.Context) {
if c.Get(gingae.UserOAuthError) != nil {
// Handle OAuth failures
}
gaeUser := c.Get(gingae.User).(user.User)
// Do stuff with the GAE User
})
http.Handle("/", r)
}