1 Star 0 Fork 0

iotas/toolkit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
proto_format
proto_parser
proto
rename
.gitignore
README.md
add_route.go
add_svc.go
ast.go
ast_util.go
code_gen.go
code_gen_test.go
collect_index.go
define.go
gen.sh
gen_md.go
gen_md_test.go
gen_router.go
gen_svc.go
init.go
inject_bson.go
inject_freq.go
inject_gorm.go
inject_json.go
inject_tag.go
inject_valitator.go
mdocserrcodes_pie.go
module_update.sh
parse_proto.go
parse_proto_test.go
parser.proto
proto_visitor.go
tpl.go
tpl_func.go
utils.go
utils_test.go
query_parser
.gitignore
LICENSE
README.md
go.mod
update_module.sh
克隆/下载
inject_freq.go 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
xuthus 提交于 4年前 . fix
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)
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/iotas/toolkit.git
git@gitee.com:iotas/toolkit.git
iotas
toolkit
toolkit
6a2c4ec13c63

搜索帮助