forked from openmeterio/openmeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (44 loc) · 1.04 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"context"
"fmt"
"os"
"time"
openmeter "github.com/openmeterio/openmeter/api/client/go"
stripe "github.com/stripe/stripe-go/v74"
)
// Stripe Key.
// Go to https://dashboard.stripe.com/test/apikeys to obtain yours
var stripeKey = os.Getenv("STRIPE_KEY") // sk_test_...""
func main() {
stripe.Key = stripeKey
if len(os.Args) == 1 {
fmt.Printf("provide argument: setup or report\n")
return
}
mode := os.Args[1]
// Setup Stripe test product, price and customer
if mode == "setup" {
err := SetupStripe()
if err != nil {
panic(err)
}
} else if mode == "report" {
// Initialize OpenMeter client
om, err := openmeter.NewClient("http://localhost:8888")
if err != nil {
panic(err.Error())
}
// Report usage
reportingFrequency := time.Second // change it in real app
report := NewReport(context.Background(), om, reportingFrequency)
err = report.Run()
if err != nil {
panic(err.Error())
}
} else {
fmt.Printf("Unknown mode: %s try: setup or report\n", mode)
}
fmt.Println("done")
os.Exit(0)
}