代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。