-
Notifications
You must be signed in to change notification settings - Fork 12
/
interface.go
26 lines (20 loc) · 910 Bytes
/
interface.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
package resources
import (
"context"
"github.com/companyzero/bisonrelay/client/clientintf"
"github.com/companyzero/bisonrelay/rpc"
)
// Provider is the interface for subsystems that provide resources.
type Provider interface {
Fulfill(ctx context.Context, uid clientintf.UserID, request *rpc.RMFetchResource) (*rpc.RMFetchResourceReply, error)
}
type providerFunc struct {
f func(ctx context.Context, uid clientintf.UserID, request *rpc.RMFetchResource) (*rpc.RMFetchResourceReply, error)
}
func (pf providerFunc) Fulfill(ctx context.Context, uid clientintf.UserID, request *rpc.RMFetchResource) (*rpc.RMFetchResourceReply, error) {
return pf.f(ctx, uid, request)
}
// ProviderFunc wraps the passed function as a Provider.
func ProviderFunc(f func(ctx context.Context, uid clientintf.UserID, request *rpc.RMFetchResource) (*rpc.RMFetchResourceReply, error)) Provider {
return providerFunc{f: f}
}