-
Notifications
You must be signed in to change notification settings - Fork 244
/
api.go
41 lines (34 loc) · 915 Bytes
/
api.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
package permissions
import (
"context"
"errors"
)
var (
// ErrServiceNotInitialized returned when permissions is not initialized/started,.
ErrServiceNotInitialized = errors.New("permissions service is not initialized")
)
func NewAPI(s *Service) *API {
return &API{s}
}
// API is class with methods available over RPC.
type API struct {
s *Service
}
func (api *API) AddDappPermissions(ctx context.Context, perms DappPermissions) error {
if api.s.db == nil {
return ErrServiceNotInitialized
}
return api.s.db.AddPermissions(perms)
}
func (api *API) GetDappPermissions(ctx context.Context) ([]DappPermissions, error) {
if api.s.db == nil {
return nil, ErrServiceNotInitialized
}
return api.s.db.GetPermissions()
}
func (api *API) DeleteDappPermissions(ctx context.Context, name string) error {
if api.s.db == nil {
return ErrServiceNotInitialized
}
return api.s.db.DeletePermission(name)
}