-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
plan.go
102 lines (91 loc) · 2.12 KB
/
plan.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package tube
import (
"fmt"
"sort"
)
type PlanKind string
const (
PlanKindNone PlanKind = ""
PlanKindTiny PlanKind = "tiny"
PlanKindSmall PlanKind = "small"
PlanKindBig PlanKind = "big"
PlanKindHuge PlanKind = "huge"
)
func (pk PlanKind) Msg() string {
return "plan_" + string(pk)
}
type Plan struct {
Kind PlanKind
Quota int64
PriceID string
}
// TODO: make configurable
var plans = map[PlanKind]Plan{
PlanKindNone: {
Kind: PlanKindNone,
Quota: 50 * 1024 * 1024 * 1024, // 50GB
},
PlanKindTiny: {
Kind: PlanKindTiny,
Quota: 50 * 1024 * 1024 * 1024, // 50GB
PriceID: "price_1NL7EFKpetgr0YLEouHdIlv1",
},
PlanKindSmall: {
Kind: PlanKindSmall,
Quota: 250 * 1024 * 1024 * 1024, // 250GB
//PriceID: "price_1I1FzcKpetgr0YLEljmXzSVH",
PriceID: "price_1I9kyKKpetgr0YLEzm17RXIp",
},
PlanKindBig: {
Kind: PlanKindBig,
Quota: 500 * 1024 * 1024 * 1024, // 500GB
//PriceID: "price_1I1G0TKpetgr0YLEyd1kx5DQ",
PriceID: "price_1I9kyDKpetgr0YLERiDJn7Kf",
},
PlanKindHuge: {
Kind: PlanKindHuge,
Quota: 2 * 1024 * 1024 * 1024 * 1024, // 2TB
// PriceID: "price_1I1G5gKpetgr0YLEj0xgvqiw",
PriceID: "price_1I9ky7Kpetgr0YLEXAiN8Kfy",
},
}
func GetPlan(kind PlanKind) Plan {
plan, ok := plans[kind]
if !ok {
panic(fmt.Errorf("no such plan: %v", kind))
}
return plan
}
func GetPlans() []Plan {
var all []Plan
for _, p := range plans {
if p.Kind == PlanKindNone {
continue
}
all = append(all, p)
}
sort.Slice(all, func(i, j int) bool {
return all[i].Quota < all[j].Quota
})
return all
}
type PlanStatus string
const (
PlanStatusActive PlanStatus = "active"
PlanStatusTrialing PlanStatus = "trialing"
PlanStatusIncomplete PlanStatus = "incomplete"
PlanStatusIncompleteExpired PlanStatus = "incomplete_expired"
PlanStatusPastDue PlanStatus = "past_due"
PlanStatusCanceled PlanStatus = "canceled"
PlanStatusUnpaid PlanStatus = "unpaid"
)
func (ps PlanStatus) Active() bool {
switch ps {
case PlanStatusActive, PlanStatusTrialing:
return true
case PlanStatusCanceled:
// TODO: double check
return false
}
return false
}