-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.go
67 lines (57 loc) · 2.56 KB
/
interfaces.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
65
66
67
//go:generate moq -out rest_mocks_test.go -pkg rest_test . Log Repository Projection CommandDispatcher EventDispatcher EventStore
package rest
import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/labstack/echo/v4"
"golang.org/x/net/context"
)
type (
//Middleware that is bound to an OpenAPI operation
Middleware func(params *MiddlewareParams) echo.MiddlewareFunc
//Controller is the handler for a specific operation
Controller func(params *ControllerParams) echo.HandlerFunc
//OperationInitializer initialzers that are run when processing OpenAPI operations
GlobalInitializer func(context.Context, *openapi3.T) (context.Context, error)
OperationInitializer func(context.Context, string, string, *openapi3.T, *openapi3.PathItem, *openapi3.Operation) (context.Context, error)
PathInitializer func(context.Context, string, *openapi3.T, *openapi3.PathItem) (context.Context, error)
CommandHandler func(ctx context.Context, command *Command, logger Log, options *CommandOptions) (response CommandResponse, err error)
EventHandler func(ctx context.Context, logger Log, event *Event) error
)
type Entity interface {
ValueObject
GetID() string
GetType() string
}
type ValueObject interface {
IsValid() bool
AddError(err error)
GetErrors() []error
}
type Repository interface {
Persist(ctxt context.Context, logger Log, resources []Resource) []error
Remove(ctxt context.Context, logger Log, resources []Resource) []error
}
type CommandDispatcher interface {
Dispatch(ctx context.Context, command *Command, logger Log, options *CommandOptions) (response CommandResponse, err error)
AddSubscriber(command CommandConfig) map[string][]CommandHandler
GetSubscribers() map[string][]CommandHandler
}
type EventDispatcher interface {
AddSubscriber(handler EventHandlerConfig) error
GetSubscribers(resourceType string) map[string][]EventHandler
Dispatch(ctx context.Context, logger Log, event *Event) []error
}
type EventStore interface {
Repository
EventDispatcher
Projection
}
type Projection interface {
GetByURI(ctxt context.Context, logger Log, uri string) (Resource, error)
// GetByKey returns a single content entity
GetByKey(ctxt context.Context, identifiers map[string]interface{}) (Resource, error)
// GetList returns a paginated result of content entities
GetList(ctx context.Context, page int, limit int, query string, sortOptions map[string]string, filterOptions map[string]interface{}) ([]Resource, int64, error)
GetByProperties(ctxt context.Context, identifiers map[string]interface{}) ([]Entity, error)
GetEventHandlers() []EventHandlerConfig
}