edge/pkg/storage/driver/rpc/server/share/find_resources.go

42 lines
953 B
Go

package share
import (
"context"
"forge.cadoles.com/arcad/edge/pkg/storage/share"
"github.com/pkg/errors"
)
type FindResourcesArgs struct {
Options *share.FindResourcesOptions
}
type FindResourcesReply struct {
Resources []*SerializableResource
}
func (s *Service) FindResources(ctx context.Context, args FindResourcesArgs, reply *FindResourcesReply) error {
resources, err := s.store.FindResources(ctx, withFindResourcesOptions(args.Options))
if err != nil {
return errors.WithStack(err)
}
serializableResources := make([]*SerializableResource, len(resources))
for resIdx, r := range resources {
serializableResources[resIdx] = FromResource(r)
}
*reply = FindResourcesReply{
Resources: serializableResources,
}
return nil
}
func withFindResourcesOptions(opts *share.FindResourcesOptions) share.FindResourcesOptionFunc {
return func(o *share.FindResourcesOptions) {
o.Name = opts.Name
o.ValueType = opts.ValueType
}
}