GetOne
This commit is contained in:
17
structful.go
17
structful.go
@@ -44,6 +44,8 @@ type IStructful interface {
|
||||
|
||||
FilterByGroup(group string, filter map[string]any) []map[string]any
|
||||
|
||||
GetOne(group, name string) map[string]any
|
||||
|
||||
CheckHash(string) bool
|
||||
|
||||
List() ([]map[string]any, error)
|
||||
@@ -109,6 +111,21 @@ func (s *Structful) GetByGroup(group string) ([]map[string]any, error) {
|
||||
return s.FilterByGroup(group, map[string]any{})
|
||||
}
|
||||
|
||||
func (s *Structful) GetOne(group, name string) (map[string]any, error) {
|
||||
filter := map[string]any{ "_name": name }
|
||||
|
||||
results, err := s.FilterByGroup(group, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(results) > 0 {
|
||||
return results[0], nil
|
||||
} else {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Structful) CheckHash(hash string) bool {
|
||||
return s.Adaptor.CheckHash(hash)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user