1
0
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:
zm
2023-03-13 19:28:37 +08:00
committed by GitHub
parent 1755dd249b
commit 924589d2da
9 changed files with 263 additions and 64 deletions

32
structutil/tag.go Normal file
View 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)
}