ducky/subscriptions

Paddy 2015-09-27 Parent:36e90e828dd0

13:1ff031bebf9e Go to Latest

ducky/subscriptions/subscriptionsd/server.go

Add golint comments. Comment on some more of our exported types, functions, and variables, both to make golint happy and because uncommented code never ever ends well.

History
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 }