ducky/subscriptions
2015-09-27
Parent:36e90e828dd0
ducky/subscriptions/subscriptionsd/server.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 main
3 import (
4 "log"
5 "net/http"
6 "os"
8 "code.secondbit.org/ducky/subscriptions.hg"
9 "code.secondbit.org/ducky/subscriptions.hg/api"
10 "code.secondbit.org/trout.hg"
12 "github.com/stripe/stripe-go"
14 "golang.org/x/net/context"
15 )
17 func main() {
18 log.SetFlags(log.LstdFlags | log.Llongfile)
19 log.Printf("Running version '%s'\n", subscriptions.Version)
20 var subscriptionStore subscriptions.SubscriptionStore
21 if os.Getenv("SUBSCRIPTIONS_PG_DB") != "" {
22 p, err := subscriptions.NewPostgres(os.Getenv("SUBSCRIPTIONS_PG_DB"))
23 if err != nil {
24 log.Fatal(err)
25 }
26 subscriptionStore = p
27 } else {
28 subscriptionStore = subscriptions.NewMemstore()
29 }
30 var stripeClient subscriptions.Stripe
31 if os.Getenv("STRIPE_KEY") != "" {
32 stripeClient = subscriptions.NewStripe(os.Getenv("STRIPE_KEY"), stripe.GetBackend(stripe.APIBackend))
33 } else {
34 log.Fatal("STRIPE_KEY environment variable must be set!")
35 }
36 c := api.WithStripeClient(stripeClient, api.WithSubscriptionStore(subscriptionStore, context.Background()))
37 router := trout.Router{}
38 api.HandleSubscriptions(&router, c)
39 http.Handle("/", router)
40 log.Println("Listening on 9001")
41 log.Fatal(http.ListenAndServe("0.0.0.0:9001", nil))
42 }