minor fixes/improvements...

This commit is contained in:
2021-12-12 02:29:29 -05:00
parent 142c0ba74f
commit 56ba974dec
6 changed files with 405 additions and 109 deletions

View File

@@ -124,7 +124,9 @@ func (s *Service) CreateCollection(label string) (collection *Collection, err er
*/
func (s *Service) GetCollection(name string) (c *Collection, err error) {
var errs []error
var colls []*Collection
var collLabel string
// First check for an alias.
if c, err = s.ReadAlias(name); err != nil && err != ErrDoesNotExist {
@@ -147,8 +149,26 @@ func (s *Service) GetCollection(name string) (c *Collection, err error) {
}
}
// Still nothing? Try by label.
for _, i := range colls {
if collLabel, err = i.Label(); err != nil {
errs = append(errs, err)
err = nil
continue
}
if collLabel == name {
c = i
return
}
}
// Couldn't find it by the given name.
err = ErrDoesNotExist
if errs != nil || len(errs) > 0 {
errs = append([]error{ErrDoesNotExist}, errs...)
err = NewErrors(errs...)
} else {
err = ErrDoesNotExist
}
return
}