mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
* add support json tag attribute for StructToMap function * add the structutil to provide more rich functions and fixed #77
33 lines
465 B
Go
33 lines
465 B
Go
package structutil
|
|
|
|
import (
|
|
"github.com/duke-git/lancet/v2/validator"
|
|
"strings"
|
|
)
|
|
|
|
type Tag struct {
|
|
Name string
|
|
Options []string
|
|
}
|
|
|
|
func newTag(tag string) *Tag {
|
|
res := strings.Split(tag, ",")
|
|
return &Tag{
|
|
Name: res[0],
|
|
Options: res[1:],
|
|
}
|
|
}
|
|
|
|
func (t *Tag) HasOption(opt string) bool {
|
|
for _, o := range t.Options {
|
|
if o == opt {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (t *Tag) IsEmpty() bool {
|
|
return validator.IsEmptyString(t.Name)
|
|
}
|