Ai
1 Star 0 Fork 0

yzsunjianguo/common_pkg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
regexp.go 916 Bytes
一键复制 编辑 原始数据 按行查看 历史
yzsunjianguo 提交于 2024-02-08 10:53 +08:00 . 初始化
package benchmark
import (
"regexp"
"strings"
)
const (
packagePattern = `\npackage (.*);`
servicePattern = `\nservice (\w+)`
methodPattern = `rpc (\w+)`
)
func getName(data []byte, pattern string) string {
re := regexp.MustCompile(pattern)
matchArr := re.FindStringSubmatch(string(data))
if len(matchArr) == 2 {
return strings.ReplaceAll(matchArr[1], " ", "")
}
return ""
}
func getMethodNames(data []byte, methodPattern string) []string {
re := regexp.MustCompile(methodPattern)
matchArr := re.FindAllStringSubmatch(string(data), -1)
names := []string{}
for _, arr := range matchArr {
if len(arr) == 2 {
names = append(names, strings.ReplaceAll(arr[1], " ", ""))
}
}
return names
}
// match name, not case-sensitive
func matchName(names []string, name string) string {
out := ""
for _, s := range names {
if strings.EqualFold(s, name) {
out = s
break
}
}
return out
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yzsunjianguo/common_pkg.git
git@gitee.com:yzsunjianguo/common_pkg.git
yzsunjianguo
common_pkg
common_pkg
v1.0.1

搜索帮助