/
contracts.go
54 lines (45 loc) · 1.5 KB
/
contracts.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
package jetflow
import (
"context"
)
// Operator is the minimal interface for all operators.
type Operator interface {
ID() string
}
// OperatorHandler handles calls to the methods of an operator.
//
// It will convert an OperatorCall to a method call and convert the result to
// a Result struct.
type OperatorHandler interface {
Handle(context.Context, OperatorClient, *Request) ([]byte, error)
}
//go:generate go run github.com/vektra/mockery/v2 --name OperatorClient --case underscore --with-expecter
type OperatorClient interface {
Find(ctx context.Context, id string, operator interface{}) error
Call(context.Context, *Request) (res []byte, err error)
}
// ProxyFactoryMapping maps type names to OperatorFactories.
type (
ProxyFactoryMapping map[string]ProxyFactory
HandlerFactoryMapping map[string]HandlerFactory
)
type (
// ProxyFactory instantiates a OperatorProxy value.
//
// Used by the OperatorClient to instantiate an operator to an OperatorProxy, so method
// calls can be proxied to the actual implementation.
ProxyFactory func(id string, client OperatorClient) Operator
HandlerFactory func(id string) OperatorHandler
)
type Publisher interface {
Publish(context.Context, *Request) (chan *Response, error)
}
type RequestHandler interface {
Handle(context.Context, *Request) *Response
}
type Storage interface {
Get(context.Context, *Request) (OperatorHandler, error)
Prepare(context.Context, *Request) error
Commit(context.Context, *Request) error
Rollback(context.Context, *Request) error
}