forked from absmach/magistrala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint.go
64 lines (54 loc) · 1.58 KB
/
endpoint.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package grpc
import (
"context"
"github.com/go-kit/kit/endpoint"
"github.com/mainflux/mainflux/things"
)
func canAccessEndpoint(svc things.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(accessByKeyReq)
if err := req.validate(); err != nil {
return nil, err
}
id, err := svc.CanAccessByKey(ctx, req.chanID, req.thingKey)
if err != nil {
return identityRes{}, err
}
return identityRes{id: id}, nil
}
}
func canAccessByIDEndpoint(svc things.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(accessByIDReq)
if err := req.validate(); err != nil {
return nil, err
}
err := svc.CanAccessByID(ctx, req.chanID, req.thingID)
return emptyRes{err: err}, err
}
}
func isChannelOwnerEndpoint(svc things.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(channelOwnerReq)
if err := req.validate(); err != nil {
return nil, err
}
err := svc.IsChannelOwner(ctx, req.owner, req.chanID)
return emptyRes{err: err}, err
}
}
func identifyEndpoint(svc things.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(identifyReq)
id, err := svc.Identify(ctx, req.key)
if err := req.validate(); err != nil {
return nil, err
}
if err != nil {
return identityRes{}, err
}
return identityRes{id: id}, nil
}
}