65 lines
947 B
Go
65 lines
947 B
Go
package domain
|
|
|
|
import (
|
|
"path"
|
|
)
|
|
|
|
type Resources []*Resource
|
|
|
|
func (r Resources) GetType(targetType string) Resources {
|
|
out := make(Resources, 0, len(r))
|
|
|
|
target, err := ParseResourceType(targetType)
|
|
if err != nil {
|
|
return out
|
|
}
|
|
|
|
for i := range r {
|
|
if r[i].resourceType != target {
|
|
continue
|
|
}
|
|
|
|
out = append(out, r[i])
|
|
}
|
|
|
|
return out
|
|
}
|
|
|
|
func (r Resources) Get(path string) *Resource {
|
|
for i := range r {
|
|
if r[i].key != path {
|
|
continue
|
|
}
|
|
|
|
return r[i]
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (r Resources) Match(pattern string) Resources {
|
|
out := make(Resources, 0, len(r))
|
|
|
|
for i := range r {
|
|
if matched, err := path.Match(pattern, r[i].key); err != nil || !matched {
|
|
continue
|
|
}
|
|
|
|
out = append(out, r[i])
|
|
}
|
|
|
|
return out
|
|
}
|
|
|
|
func (r Resources) GetMatch(pattern string) *Resource {
|
|
for i := range r {
|
|
if matched, err := path.Match(pattern, r[i].key); err != nil || !matched {
|
|
continue
|
|
}
|
|
|
|
return r[i]
|
|
}
|
|
|
|
return nil
|
|
}
|