2 Star 0 Fork 0

djienet / kratos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tags.go 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
chenli 提交于 2020-11-02 15:31 . init
package tag
import (
"reflect"
"strings"
)
// GetCommentWithoutTag strip tags in comment
func GetCommentWithoutTag(comment string) []string {
var lines []string
if comment == "" {
return lines
}
split := strings.Split(strings.TrimRight(comment, "\n\r"), "\n")
for _, line := range split {
tag, _, _ := GetLineTag(line)
if tag == "" {
lines = append(lines, line)
}
}
return lines
}
func GetTagsInComment(comment string) []reflect.StructTag {
split := strings.Split(comment, "\n")
var tagsInComment []reflect.StructTag
for _, line := range split {
tag, _, _ := GetLineTag(line)
if tag != "" {
tagsInComment = append(tagsInComment, tag)
}
}
return tagsInComment
}
func GetTagValue(key string, tags []reflect.StructTag) string {
for _, t := range tags {
val := t.Get(key)
if val != "" {
return val
}
}
return ""
}
// find tag between backtick, start & end is the position of backtick
func GetLineTag(line string) (tag reflect.StructTag, start int, end int) {
start = strings.Index(line, "`")
end = strings.LastIndex(line, "`")
if end <= start {
return
}
tag = reflect.StructTag(line[start+1 : end])
return
}
1
https://gitee.com/djienet/kratos.git
git@gitee.com:djienet/kratos.git
djienet
kratos
kratos
v1.1.7

搜索帮助