ducky/subscriptions
ducky/subscriptions/api/context_helpers.go
Add comments, move ChangingSystemProperties to the api package. Add comments to all our exported types and variables in subscription.go, both to make golint happy and because it's good to have comments. Move the subscriptions.ChangingSystemProperties helper to api.changingSystemProperties, because it returns API-specific strings and there's no real reason it has to be in the subscriptions package--everything it needs to work on is exported.
1 package api
3 import (
4 "errors"
6 "code.secondbit.org/ducky/subscriptions.hg"
8 "golang.org/x/net/context"
9 )
11 const (
12 subscriptionStoreKey = "SubscriptionStore"
13 stripeKey = "Stripe"
14 )
16 var (
17 ErrSubscriptionStoreNotSet = errors.New("SubscriptionStore not set")
18 ErrStripeClientNotSet = errors.New("Stripe not set")
19 )
21 func getSubscriptionStore(c context.Context) (subscriptions.SubscriptionStore, error) {
22 store := c.Value(subscriptionStoreKey)
23 if store == nil {
24 return nil, ErrSubscriptionStoreNotSet
25 }
26 if s, ok := store.(subscriptions.SubscriptionStore); ok {
27 return s, nil
28 }
29 return nil, ErrSubscriptionStoreNotSet
30 }
32 func WithSubscriptionStore(store subscriptions.SubscriptionStore, c context.Context) context.Context {
33 return context.WithValue(c, subscriptionStoreKey, store)
34 }
36 func getStripeClient(c context.Context) (subscriptions.Stripe, error) {
37 stripe := c.Value(stripeKey)
38 if stripe == nil {
39 return subscriptions.Stripe{}, ErrStripeClientNotSet
40 }
41 if s, ok := stripe.(subscriptions.Stripe); ok {
42 return s, nil
43 }
44 return subscriptions.Stripe{}, ErrStripeClientNotSet
45 }
47 func WithStripeClient(stripe subscriptions.Stripe, c context.Context) context.Context {
48 return context.WithValue(c, stripeKey, stripe)
49 }