func GetDB(ctx context.Context) *gorm.DB {
	obj := ctx.Value(dbKey)
	if obj == nil {
		return nil
	}
	return obj.(*gorm.DB)
}
GetDB reads the database from the context.
package context
import (
	"fmt"
	"context"
	"github.com/dgrijalva/jwt-go"
	"github.com/jinzhu/gorm"
	"github.com/netlify/gocommerce/assetstores"
	"github.com/netlify/gocommerce/claims"
	"github.com/netlify/gocommerce/conf"
	"github.com/netlify/gocommerce/coupons"
	"github.com/netlify/gocommerce/mailer"
	"github.com/netlify/gocommerce/models"
	"github.com/netlify/gocommerce/payments"
)
type contextKey string
func (c contextKey) String() string {
	return "api context key " + string(c)
}
const (
	tokenKey           = contextKey("jwt")
	configKey          = contextKey("config")
	couponsKey         = contextKey("coupons")
	requestIDKey       = contextKey("request_id")
	adminFlagKey       = contextKey("is_admin")
	mailerKey          = contextKey("mailer")
	assetStoreKey      = contextKey("asset_store")
	paymentProviderKey = contextKey("payment-provider")
	userIDKey          = contextKey("user_id")
	userKey            = contextKey("user")
	orderIDKey         = contextKey("order_id")
	instanceIDKey      = contextKey("instance_id")
	instanceKey        = contextKey("instance")
	dbKey              = contextKey("db")
)
func WithConfig(ctx context.Context, config *conf.Configuration) context.Context {
	return context.WithValue(ctx, configKey, config)
}
func GetConfig(ctx context.Context) *conf.Configuration {
	obj := ctx.Value(configKey)
	if obj == nil {
		return nil
	}
	return obj.(*conf.Configuration)
}
func WithCoupons(ctx context.Context, config *conf.Configuration) (context.Context, error) {
	cache, err := coupons.NewCouponCacheFromURL(config)
	if err != nil {
		return nil, err
	}
	return context.WithValue(ctx, couponsKey, cache), nil
}
func GetCoupons(ctx context.Context) coupons.Cache {
	obj := ctx.Value(couponsKey)
	if obj == nil {
		return nil
	}
	return obj.(coupons.Cache)
}
func WithToken(ctx context.Context, token *jwt.Token) context.Context {
	return context.WithValue(ctx, tokenKey, token)
}
func GetToken(ctx context.Context) *jwt.Token {
	obj := ctx.Value(tokenKey)
	if obj == nil {
		return nil
	}
	return obj.(*jwt.Token)
}
func WithRequestID(ctx context.Context, id string) context.Context {
	return context.WithValue(ctx, requestIDKey, id)
}
func GetRequestID(ctx context.Context) string {
	obj := ctx.Value(requestIDKey)
	if obj == nil {
		return ""
	}
	return obj.(string)
}
func WithMailer(ctx context.Context, mailer mailer.Mailer) context.Context {
	return context.WithValue(ctx, mailerKey, mailer)
}
func GetMailer(ctx context.Context) mailer.Mailer {
	obj := ctx.Value(mailerKey)
	if obj == nil {
		return nil
	}
	return obj.(mailer.Mailer)
}
func WithAssetStore(ctx context.Context, store assetstores.Store) context.Context {
	return context.WithValue(ctx, assetStoreKey, store)
}
func GetAssetStore(ctx context.Context) assetstores.Store {
	obj := ctx.Value(assetStoreKey)
	if obj == nil {
		return nil
	}
	return obj.(assetstores.Store)
}
func WithPaymentProviders(ctx context.Context, provs map[string]payments.Provider) context.Context {
	return context.WithValue(ctx, paymentProviderKey, provs)
}
func GetPaymentProviders(ctx context.Context) map[string]payments.Provider {
	provs, _ := ctx.Value(paymentProviderKey).(map[string]payments.Provider)
	return provs
}
func GetClaims(ctx context.Context) *claims.JWTClaims {
	token := GetToken(ctx)
	if token == nil {
		return nil
	}
	return token.Claims.(*claims.JWTClaims)
}
func GetClaimsAsMap(ctx context.Context) map[string]interface{} {
	token := GetToken(ctx)
	if token == nil {
		return nil
	}
	config := GetConfig(ctx)
	if config == nil {
		return nil
	}
	claims := jwt.MapClaims{}
	_, err := jwt.ParseWithClaims(token.Raw, &claims, func(token *jwt.Token) (interface{}, error) {
		if token.Header["alg"] != jwt.SigningMethodHS256.Name {
			return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
		}
		return []byte(config.JWT.Secret), nil
	})
	if err != nil {
		return nil
	}
	return map[string]interface{}(claims)
}
func WithAdminFlag(ctx context.Context, isAdmin bool) context.Context {
	return context.WithValue(ctx, adminFlagKey, isAdmin)
}
func IsAdmin(ctx context.Context) bool {
	obj := ctx.Value(adminFlagKey)
	if obj == nil {
		return false
	}
	return obj.(bool)
}
func GetUserID(ctx context.Context) string {
	id, _ := ctx.Value(userIDKey).(string)
	return id
}
func WithUserID(ctx context.Context, userID string) context.Context {
	return context.WithValue(ctx, userIDKey, userID)
}
func GetUser(ctx context.Context) *models.User {
	u := ctx.Value(userKey)
	if u == nil {
		return nil
	}
	return u.(*models.User)
}
func WithUser(ctx context.Context, user *models.User) context.Context {
	return context.WithValue(ctx, userKey, user)
}
func GetOrderID(ctx context.Context) string {
	id, _ := ctx.Value(orderIDKey).(string)
	return id
}
func WithOrderID(ctx context.Context, orderID string) context.Context {
	return context.WithValue(ctx, orderIDKey, orderID)
}
func WithInstanceID(ctx context.Context, id string) context.Context {
	return context.WithValue(ctx, instanceIDKey, id)
}
func GetInstanceID(ctx context.Context) string {
	obj := ctx.Value(instanceIDKey)
	if obj == nil {
		return ""
	}
	return obj.(string)
}
func WithInstance(ctx context.Context, i *models.Instance) context.Context {
	return context.WithValue(ctx, instanceKey, i)
}
func GetInstance(ctx context.Context) *models.Instance {
	obj := ctx.Value(instanceKey)
	if obj == nil {
		return nil
	}
	return obj.(*models.Instance)
}