package raxmiddleware import ( "net/http" "github.com/gin-gonic/gin" "github.rackspace.com/gorax/clients/dcxSwitchapi" ) // CtxSwitchAPI defines the key to store in the gin.Context const CtxSwitchAPI = "switchapi" // SwitchAPI function initiates a SwitchAPI client and embeds it into the gin context func SwitchAPI(username, password string) gin.HandlerFunc { return func(c *gin.Context) { switchAPI, err := dcxSwitchapi.NewClient(username, password) if err != nil { AddError(c, http.StatusUnauthorized, err.Error()) return } c.Set(CtxSwitchAPI, switchAPI) } }