package raxmiddleware import ( "net/http" "github.com/gin-gonic/gin" "github.rackspace.com/gorax/clients/goctk" ) // CtxCTK defines the key to store in the gin.Context const CtxCTK = "ctk" // CTK function initiates a CTK client and embeds it into the gin context func CTK(username, password string, staging bool) gin.HandlerFunc { return func(c *gin.Context) { ctkClient, err := goctk.NewCTK(goctk.SSO(username, password), goctk.WithStaging(staging)) if err != nil { AddError(c, http.StatusUnauthorized, err.Error()) return } c.Set(CtxCTK, ctkClient) } }