-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
gstructs_field_tag.go
90 lines (79 loc) · 2.06 KB
/
gstructs_field_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gstructs
import (
"strings"
"github.com/gogf/gf/v2/util/gtag"
)
// TagJsonName returns the `json` tag name string of the field.
func (f *Field) TagJsonName() string {
if jsonTag := f.Tag(gtag.Json); jsonTag != "" {
return strings.Split(jsonTag, ",")[0]
}
return ""
}
// TagDefault returns the most commonly used tag `default/d` value of the field.
func (f *Field) TagDefault() string {
v := f.Tag(gtag.Default)
if v == "" {
v = f.Tag(gtag.DefaultShort)
}
return v
}
// TagParam returns the most commonly used tag `param/p` value of the field.
func (f *Field) TagParam() string {
v := f.Tag(gtag.Param)
if v == "" {
v = f.Tag(gtag.ParamShort)
}
return v
}
// TagValid returns the most commonly used tag `valid/v` value of the field.
func (f *Field) TagValid() string {
v := f.Tag(gtag.Valid)
if v == "" {
v = f.Tag(gtag.ValidShort)
}
return v
}
// TagDescription returns the most commonly used tag `description/des/dc` value of the field.
func (f *Field) TagDescription() string {
v := f.Tag(gtag.Description)
if v == "" {
v = f.Tag(gtag.DescriptionShort)
}
if v == "" {
v = f.Tag(gtag.DescriptionShort2)
}
return v
}
// TagSummary returns the most commonly used tag `summary/sum/sm` value of the field.
func (f *Field) TagSummary() string {
v := f.Tag(gtag.Summary)
if v == "" {
v = f.Tag(gtag.SummaryShort)
}
if v == "" {
v = f.Tag(gtag.SummaryShort2)
}
return v
}
// TagAdditional returns the most commonly used tag `additional/ad` value of the field.
func (f *Field) TagAdditional() string {
v := f.Tag(gtag.Additional)
if v == "" {
v = f.Tag(gtag.AdditionalShort)
}
return v
}
// TagExample returns the most commonly used tag `example/eg` value of the field.
func (f *Field) TagExample() string {
v := f.Tag(gtag.Example)
if v == "" {
v = f.Tag(gtag.ExampleShort)
}
return v
}