代码拉取完成,页面将自动刷新
package proto_parser
import (
"fmt"
"github.com/emicklei/proto"
"regexp"
"strings"
)
func injectFreqMap(svc *proto.Service) {
if len(svc.Elements) == 0 {
return
}
if svc.Comment == nil || len(svc.Comment.Lines) == 0 {
return
}
// 取路由前缀
prefix := getSvcRouterAPI(svc.Comment.Lines)
for _, element := range svc.Elements {
rpc, ok := element.(*proto.RPC)
if !ok {
continue
}
if rpc.Comment == nil || len(rpc.Comment.Lines) == 0 {
continue
}
doc := rpc.Comment.Lines
suffix := getRpcRouterAPI(doc)
for _, c := range doc {
if strings.Contains(c, "@freq") {
r := regexp.MustCompile(RegexpFreq)
res := r.FindAllStringSubmatch(c, -1)
if len(res) != 1 {
fmt.Println("限频格式错误: ", c)
continue
}
if len(res[0]) != 2 {
fmt.Println("限频格式错误: ", c)
continue
}
freqData := trim(res[0][1])
freqS := strings.Split(freqData, " ")
if len(freqS) != 3 {
fmt.Println("限频格式错误: ", freqS)
continue
}
c := FreqConfig{
Minute: string2Int64(freqS[0]),
Hour: string2Int64(freqS[1]),
Day: string2Int64(freqS[2]),
}
Visitor.AddFreq(fmt.Sprintf("%s%s", prefix, suffix), c)
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。