This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
types.go
48 lines (38 loc) · 1.65 KB
/
types.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
///////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
///////////////////////////////////////////////////////////////////////
package events
import (
"context"
"io"
)
// NO TESTS
// Transport is an abstraction over possible implementation of messaging
type Transport interface {
// Publish publishes the event using the underlying transport
Publish(ctx context.Context, event *CloudEvent, topic string, organization string) error
// Subscribe takes a handler to run on every event received on topic. Returns a cancelable Subscription
Subscribe(ctx context.Context, topic string, organization string, handler Handler) (Subscription, error)
Close()
}
// Handler is a callback function used to handle received event
type Handler func(context.Context, *CloudEvent)
// Subscription represents an active subscription within Transport. Subscription can be stopped
// by calling Unsubscribe()
type Subscription interface {
GetTopic() string
Unsubscribe() error
GetOrganization() string
}
// Validator takes a CloudEvent and validates it. Although CloudEvent struct includes tags following
// go-playground/validator convention, validation schema is up to the implementation.
type Validator interface {
Validate(event *CloudEvent) error
}
// StreamParser takes io.Reader and returns slice of CloudEvents. It is up to the implementation
// whether incorrect CloudEvent should be omitted from slice, or error should be returned.
// If error is returned, events slice is expected to be nil.
type StreamParser interface {
Parse(io.Reader) ([]CloudEvent, error)
}