From f79f859517cc5d9370404082120681ff963a0053 Mon Sep 17 00:00:00 2001 From: George Suntres Date: Fri, 10 Apr 2026 21:40:55 -0400 Subject: [PATCH] GetOne --- structful.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/structful.go b/structful.go index 2796748..ca3e0aa 100644 --- a/structful.go +++ b/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) }