forked from lilith44/gox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.go
52 lines (41 loc) · 839 Bytes
/
tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package gox
import "strings"
type (
// BaseTag Tag基础
BaseTag struct {
options []string
}
// Tagger 支持Tag的接口
Tagger interface {
Contains(option string) (contains bool)
}
)
// Contains 判断Tag是否包含某个属性
func (tag *BaseTag) Contains(option string) (contains bool) {
contains = false
for _, opt := range tag.options {
if strings.ToLower(opt) == option {
contains = true
break
}
}
return
}
// NamedTag 描述Golang的Tag标记
type NamedTag struct {
BaseTag
name string
}
// NewTag 创建新Tag
func NewNamedTag(tagString string) *NamedTag {
tagArray := strings.Split(tagString, ",")
tag := &NamedTag{
BaseTag: BaseTag{options: tagArray[1:]},
name: tagArray[0],
}
return tag
}
// GetName 获得Tag的名称
func (tag *NamedTag) GetName() string {
return tag.name
}