mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-10 15:52:27 +08:00
Add StructUtil for provide more rich functions (#79)
* add support json tag attribute for StructToMap function * add the structutil to provide more rich functions and fixed #77
This commit is contained in:
32
structutil/tag.go
Normal file
32
structutil/tag.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user