mirror of
https://github.com/strongdm/comply
synced 2024-09-19 10:35:39 +00:00
33 lines
696 B
Go
33 lines
696 B
Go
|
package structs
|
||
|
|
||
|
import "strings"
|
||
|
|
||
|
// tagOptions contains a slice of tag options
|
||
|
type tagOptions []string
|
||
|
|
||
|
// Has returns true if the given optiton is available in tagOptions
|
||
|
func (t tagOptions) Has(opt string) bool {
|
||
|
for _, tagOpt := range t {
|
||
|
if tagOpt == opt {
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
// parseTag splits a struct field's tag into its name and a list of options
|
||
|
// which comes after a name. A tag is in the form of: "name,option1,option2".
|
||
|
// The name can be neglectected.
|
||
|
func parseTag(tag string) (string, tagOptions) {
|
||
|
// tag is one of followings:
|
||
|
// ""
|
||
|
// "name"
|
||
|
// "name,opt"
|
||
|
// "name,opt,opt2"
|
||
|
// ",opt"
|
||
|
|
||
|
res := strings.Split(tag, ",")
|
||
|
return res[0], res[1:]
|
||
|
}
|