ducky/subscriptions
2015-10-04
Parent:36e90e828dd0
ducky/subscriptions/subscriptionsd/server.go
Document our client to make golint happy. Take care of all the documentation warnings in the client subpackage, which means golint now returns successfully.
| paddy@4 | 1 package main |
| paddy@4 | 2 |
| paddy@4 | 3 import ( |
| paddy@4 | 4 "log" |
| paddy@4 | 5 "net/http" |
| paddy@4 | 6 "os" |
| paddy@4 | 7 |
| paddy@4 | 8 "code.secondbit.org/ducky/subscriptions.hg" |
| paddy@4 | 9 "code.secondbit.org/ducky/subscriptions.hg/api" |
| paddy@4 | 10 "code.secondbit.org/trout.hg" |
| paddy@4 | 11 |
| paddy@4 | 12 "github.com/stripe/stripe-go" |
| paddy@4 | 13 |
| paddy@4 | 14 "golang.org/x/net/context" |
| paddy@4 | 15 ) |
| paddy@4 | 16 |
| paddy@4 | 17 func main() { |
| paddy@4 | 18 log.SetFlags(log.LstdFlags | log.Llongfile) |
| paddy@4 | 19 log.Printf("Running version '%s'\n", subscriptions.Version) |
| paddy@4 | 20 var subscriptionStore subscriptions.SubscriptionStore |
| paddy@4 | 21 if os.Getenv("SUBSCRIPTIONS_PG_DB") != "" { |
| paddy@4 | 22 p, err := subscriptions.NewPostgres(os.Getenv("SUBSCRIPTIONS_PG_DB")) |
| paddy@4 | 23 if err != nil { |
| paddy@4 | 24 log.Fatal(err) |
| paddy@4 | 25 } |
| paddy@4 | 26 subscriptionStore = p |
| paddy@4 | 27 } else { |
| paddy@4 | 28 subscriptionStore = subscriptions.NewMemstore() |
| paddy@4 | 29 } |
| paddy@4 | 30 var stripeClient subscriptions.Stripe |
| paddy@4 | 31 if os.Getenv("STRIPE_KEY") != "" { |
| paddy@4 | 32 stripeClient = subscriptions.NewStripe(os.Getenv("STRIPE_KEY"), stripe.GetBackend(stripe.APIBackend)) |
| paddy@4 | 33 } else { |
| paddy@4 | 34 log.Fatal("STRIPE_KEY environment variable must be set!") |
| paddy@4 | 35 } |
| paddy@4 | 36 c := api.WithStripeClient(stripeClient, api.WithSubscriptionStore(subscriptionStore, context.Background())) |
| paddy@4 | 37 router := trout.Router{} |
| paddy@4 | 38 api.HandleSubscriptions(&router, c) |
| paddy@4 | 39 http.Handle("/", router) |
| paddy@4 | 40 log.Println("Listening on 9001") |
| paddy@4 | 41 log.Fatal(http.ListenAndServe("0.0.0.0:9001", nil)) |
| paddy@4 | 42 } |