101 lines
2.3 KiB
Go
101 lines
2.3 KiB
Go
|
|
package config
|
||
|
|
|
||
|
|
type Tier string
|
||
|
|
|
||
|
|
const (
|
||
|
|
TierFree Tier = "free"
|
||
|
|
TierPro Tier = "pro"
|
||
|
|
)
|
||
|
|
|
||
|
|
type TierConfig struct {
|
||
|
|
Name string `json:"name"`
|
||
|
|
Description string `json:"description"`
|
||
|
|
MonthlyPrice int `json:"monthly_price"`
|
||
|
|
AnnualPrice int `json:"annual_price"`
|
||
|
|
CustomDomain bool `json:"custom_domain"`
|
||
|
|
BadgeRequired bool `json:"badge_required"`
|
||
|
|
AnalyticsRetention int `json:"analytics_retention"`
|
||
|
|
APIRateLimit int `json:"api_rate_limit"`
|
||
|
|
MaxWebhooks int `json:"max_webhooks"`
|
||
|
|
WebhookDeliveries int `json:"webhook_deliveries"`
|
||
|
|
MaxPlugins int `json:"max_plugins"`
|
||
|
|
PluginExecutions int `json:"plugin_executions"`
|
||
|
|
}
|
||
|
|
|
||
|
|
var Tiers = map[Tier]TierConfig{
|
||
|
|
TierFree: {
|
||
|
|
Name: "Free",
|
||
|
|
Description: "For getting started",
|
||
|
|
MonthlyPrice: 0,
|
||
|
|
AnnualPrice: 0,
|
||
|
|
CustomDomain: false,
|
||
|
|
BadgeRequired: true,
|
||
|
|
AnalyticsRetention: 7,
|
||
|
|
APIRateLimit: 100,
|
||
|
|
MaxWebhooks: 3,
|
||
|
|
WebhookDeliveries: 100,
|
||
|
|
MaxPlugins: 3,
|
||
|
|
PluginExecutions: 1000,
|
||
|
|
},
|
||
|
|
TierPro: {
|
||
|
|
Name: "Pro",
|
||
|
|
Description: "For serious bloggers",
|
||
|
|
MonthlyPrice: 500,
|
||
|
|
AnnualPrice: 4900,
|
||
|
|
CustomDomain: true,
|
||
|
|
BadgeRequired: false,
|
||
|
|
AnalyticsRetention: 90,
|
||
|
|
APIRateLimit: 1000,
|
||
|
|
MaxWebhooks: 10,
|
||
|
|
WebhookDeliveries: 1000,
|
||
|
|
MaxPlugins: 10,
|
||
|
|
PluginExecutions: 10000,
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
func GetTier(premium bool) Tier {
|
||
|
|
if premium {
|
||
|
|
return TierPro
|
||
|
|
}
|
||
|
|
return TierFree
|
||
|
|
}
|
||
|
|
|
||
|
|
func GetConfig(tier Tier) TierConfig {
|
||
|
|
if cfg, ok := Tiers[tier]; ok {
|
||
|
|
return cfg
|
||
|
|
}
|
||
|
|
return Tiers[TierFree]
|
||
|
|
}
|
||
|
|
|
||
|
|
type TierInfo struct {
|
||
|
|
Tier Tier `json:"tier"`
|
||
|
|
Config TierConfig `json:"config"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func GetTierInfo(premium bool) TierInfo {
|
||
|
|
tier := GetTier(premium)
|
||
|
|
return TierInfo{
|
||
|
|
Tier: tier,
|
||
|
|
Config: GetConfig(tier),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
type Usage struct {
|
||
|
|
Webhooks int `json:"webhooks"`
|
||
|
|
Plugins int `json:"plugins"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type AllTiersResponse struct {
|
||
|
|
CurrentTier Tier `json:"current_tier"`
|
||
|
|
Tiers map[Tier]TierConfig `json:"tiers"`
|
||
|
|
Usage Usage `json:"usage"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func GetAllTiers(premium bool, usage Usage) AllTiersResponse {
|
||
|
|
return AllTiersResponse{
|
||
|
|
CurrentTier: GetTier(premium),
|
||
|
|
Tiers: Tiers,
|
||
|
|
Usage: usage,
|
||
|
|
}
|
||
|
|
}
|