mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-02-11 17:15:38 +08:00
将带宽限制改为流量限制
This commit is contained in:
@@ -5,13 +5,13 @@ package serverconfigs
|
||||
type PlanPriceType = string
|
||||
|
||||
const (
|
||||
PlanPriceTypeBandwidth PlanPriceType = "bandwidth"
|
||||
PlanPriceTypePeriod PlanPriceType = "period"
|
||||
PlanPriceTypeTraffic PlanPriceType = "traffic"
|
||||
PlanPriceTypePeriod PlanPriceType = "period"
|
||||
)
|
||||
|
||||
func FindPlanPriceTypeName(priceType PlanPriceType) string {
|
||||
switch priceType {
|
||||
case PlanPriceTypeBandwidth:
|
||||
case PlanPriceTypeTraffic:
|
||||
return "带宽用量"
|
||||
case PlanPriceTypePeriod:
|
||||
return "时间周期"
|
||||
@@ -19,6 +19,6 @@ func FindPlanPriceTypeName(priceType PlanPriceType) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
type PlanBandwidthPrice struct {
|
||||
type PlanTrafficPrice struct {
|
||||
Base float32 `yaml:"base" json:"base"` // 基础价格,单位是 元/GB
|
||||
}
|
||||
|
||||
@@ -42,9 +42,9 @@ type ServerConfig struct {
|
||||
HTTPCachePolicyId int64 `yaml:"httpCachePolicyId" json:"httpCachePolicyId"`
|
||||
HTTPCachePolicy *HTTPCachePolicy `yaml:"httpCachePolicy" json:"httpCachePolicy"` // 通过 HTTPCachePolicyId 获取
|
||||
|
||||
// 带宽限制
|
||||
BandwidthLimit *BandwidthLimitConfig `yaml:"bandwidthLimit" json:"bandwidthLimit"`
|
||||
BandwidthLimitStatus *BandwidthLimitStatus `yaml:"bandwidthLimitStatus" json:"bandwidthLimitStatus"`
|
||||
// 流量限制
|
||||
TrafficLimit *TrafficLimitConfig `yaml:"trafficLimit" json:"trafficLimit"`
|
||||
TrafficLimitStatus *TrafficLimitStatus `yaml:"trafficLimitStatus" json:"trafficLimitStatus"`
|
||||
|
||||
// 套餐
|
||||
UserPlan *UserPlanConfig `yaml:"userPlan" json:"userPlan"`
|
||||
|
||||
@@ -4,20 +4,20 @@ package serverconfigs
|
||||
|
||||
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
|
||||
// DefaultBandwidthLimitNoticePageBody 达到带宽限制时默认提示内容
|
||||
const DefaultBandwidthLimitNoticePageBody = `<!DOCTYPE html>
|
||||
// DefaultTrafficLimitNoticePageBody 达到流量限制时默认提示内容
|
||||
const DefaultTrafficLimitNoticePageBody = `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bandwidth Limit Exceeded Warning/title>
|
||||
<title>Traffic Limit Exceeded Warning/title>
|
||||
<body>
|
||||
|
||||
The site bandwidth has exceeded the limit. Please contact with the site administrator.
|
||||
The site traffic has exceeded the limit. Please contact with the site administrator.
|
||||
|
||||
</body>
|
||||
</html>`
|
||||
|
||||
// BandwidthLimitConfig 带宽限制
|
||||
type BandwidthLimitConfig struct {
|
||||
// TrafficLimitConfig 流量限制
|
||||
type TrafficLimitConfig struct {
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
|
||||
|
||||
DailySize *shared.SizeCapacity `yaml:"dailySize" json:"dailySize"` // 每日限制
|
||||
@@ -29,7 +29,7 @@ type BandwidthLimitConfig struct {
|
||||
|
||||
// DailyBytes 每天限制
|
||||
// 不使用Init()来初始化数据,是为了让其他地方不经过Init()也能得到计算值
|
||||
func (this *BandwidthLimitConfig) DailyBytes() int64 {
|
||||
func (this *TrafficLimitConfig) DailyBytes() int64 {
|
||||
if this.DailySize != nil {
|
||||
return this.DailySize.Bytes()
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func (this *BandwidthLimitConfig) DailyBytes() int64 {
|
||||
}
|
||||
|
||||
// MonthlyBytes 每月限制
|
||||
func (this *BandwidthLimitConfig) MonthlyBytes() int64 {
|
||||
func (this *TrafficLimitConfig) MonthlyBytes() int64 {
|
||||
if this.MonthlySize != nil {
|
||||
return this.MonthlySize.Bytes()
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func (this *BandwidthLimitConfig) MonthlyBytes() int64 {
|
||||
}
|
||||
|
||||
// TotalBytes 总限制
|
||||
func (this *BandwidthLimitConfig) TotalBytes() int64 {
|
||||
func (this *TrafficLimitConfig) TotalBytes() int64 {
|
||||
if this.TotalSize != nil {
|
||||
return this.TotalSize.Bytes()
|
||||
}
|
||||
@@ -53,6 +53,6 @@ func (this *BandwidthLimitConfig) TotalBytes() int64 {
|
||||
}
|
||||
|
||||
// IsEmpty 检查是否有限制值
|
||||
func (this *BandwidthLimitConfig) IsEmpty() bool {
|
||||
func (this *TrafficLimitConfig) IsEmpty() bool {
|
||||
return !this.IsOn || (this.DailyBytes() <= 0 && this.MonthlyBytes() <= 0 && this.TotalBytes() <= 0)
|
||||
}
|
||||
@@ -4,12 +4,12 @@ package serverconfigs
|
||||
|
||||
import timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
|
||||
// BandwidthLimitStatus 带宽限制状态
|
||||
type BandwidthLimitStatus struct {
|
||||
// TrafficLimitStatus 流量限制状态
|
||||
type TrafficLimitStatus struct {
|
||||
UntilDay string `yaml:"untilDay" json:"untilDay"` // 有效日期,格式YYYYMMDD
|
||||
}
|
||||
|
||||
func (this *BandwidthLimitStatus) IsValid() bool {
|
||||
func (this *TrafficLimitStatus) IsValid() bool {
|
||||
if len(this.UntilDay) == 0 {
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user