Skip to content

Gin middleware, handling Google App Engine integration

License

Notifications You must be signed in to change notification settings

frankbille/gingae

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gin GAE Middleware Build Status GoDoc Coverage Status

Gin middlewares providing Google App Engine integrations.

Provided middlewares

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.

Usage

You always have to include GAE Context, as all the others depend on that.

GAE Context

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)
}

GAE User (standard)

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)
}

GAE User (OAuth)

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)
}

About

Gin middleware, handling Google App Engine integration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages