-
Notifications
You must be signed in to change notification settings - Fork 178
/
services.go
36 lines (29 loc) · 991 Bytes
/
services.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package meta
import (
"context"
"github.com/pydio/cells/v4/common/runtime"
servercontext "github.com/pydio/cells/v4/common/server/context"
"github.com/pydio/cells/v4/common/log"
pb "github.com/pydio/cells/v4/common/proto/registry"
"github.com/pydio/cells/v4/common/registry"
)
func servicesWithMeta(ctx context.Context, metaName string, metaValue string) ([]registry.Service, error) {
reg := servercontext.GetRegistry(ctx)
if reg == nil {
defaultReg, err := registry.OpenRegistry(context.Background(), runtime.RegistryURL())
if err != nil {
return nil, err
}
reg = defaultReg
log.Logger(context.Background()).Warn("servicesWithMeta called empty registry, will use default, this is not recommended")
}
items, e := reg.List(registry.WithType(pb.ItemType_SERVICE), registry.WithMeta(metaName, metaValue))
if e != nil {
return nil, e
}
var res []registry.Service
for _, item := range items {
res = append(res, item.(registry.Service))
}
return res, nil
}