daShangDao_planA/planB/initialization/speed/speed.go

33 lines
665 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package speed
import (
"planA/planB/initialization/golabl"
"golang.org/x/time/rate"
)
// Init 初始化 限速器
func Init() {
//默认为18
speed := 18
//根据平台设置速率
switch golabl.Task.Header.ShopType {
case "1":
speed = golabl.Config.Speed.PddSpeed
//case 2:
case "5":
speed = golabl.Config.Speed.XianyuSpeed
default:
speed = 18
}
//如果需要打水印则速率下降为10
if golabl.Task.Header.ShopMsg.WatermarkImgUrl != "" && golabl.Task.Header.ShopType == "1" {
speed = golabl.Config.Speed.Watermark
if speed == 0 {
speed = 10
}
}
//初始化限速器
golabl.Speed = rate.NewLimiter(rate.Limit(speed), 1)
}