types

package
v0.0.0-...-7f64854 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCredentials

func GetCredentials() *auth.BasicAuthCredentials

func MakeClient

func MakeClient(timeout time.Duration) *http.Client

MakeClient returns a http.Client with a timeout for connection establishing and request handling

Types

type Controller

type Controller interface {
	Subscribe(subscriber ResponseSubscriber)
	Invoke(topic string, message *[]byte)
	InvokeWithContext(ctx context.Context, topic string, message *[]byte)
	BeginMapBuilder()
	Topics() []string
}

Controller is used to invoke functions on a per-topic basis and to subscribe to responses returned by said functions.

func NewController

func NewController(credentials *auth.BasicAuthCredentials, config *ControllerConfig) Controller

NewController create a new connector SDK controller

type ControllerConfig

type ControllerConfig struct {
	// UpstreamTimeout controls maximum timeout invoking a function via the gateway
	UpstreamTimeout time.Duration

	//  GatewayURL is the remote OpenFaaS gateway
	GatewayURL string

	// PrintResponse if true prints the function responses
	PrintResponse bool

	// PrintResponseBody if true prints the function response body to stdout
	PrintResponseBody bool

	// RebuildInterval the interval at which the topic map is rebuilt
	RebuildInterval time.Duration

	// TopicAnnotationDelimiter defines the character upon which to split the Topic annotation value
	TopicAnnotationDelimiter string

	// AsyncFunctionInvocation if true points to the asynchronous function route
	AsyncFunctionInvocation bool

	// PrintSync indicates whether the sync should be logged.
	PrintSync bool
}

ControllerConfig configures a connector SDK controller

type FunctionLookupBuilder

type FunctionLookupBuilder struct {
	GatewayURL     string
	Client         *http.Client
	Credentials    *auth.BasicAuthCredentials
	TopicDelimiter string
}

FunctionLookupBuilder builds a list of OpenFaaS functions

func (*FunctionLookupBuilder) Build

func (s *FunctionLookupBuilder) Build() (map[string][]string, error)

Build compiles a map of topic names and functions that have advertised to receive messages on said topic

type Invoker

type Invoker struct {
	PrintResponse bool
	Client        *http.Client
	GatewayURL    string
	Responses     chan InvokerResponse
}

func NewInvoker

func NewInvoker(gatewayURL string, client *http.Client, printResponse bool) *Invoker

func (*Invoker) Invoke

func (i *Invoker) Invoke(topicMap *TopicMap, topic string, message *[]byte)

Invoke triggers a function by accessing the API Gateway

func (*Invoker) InvokeWithContext

func (i *Invoker) InvokeWithContext(ctx context.Context, topicMap *TopicMap, topic string, message *[]byte)

InvokeWithContext triggers a function by accessing the API Gateway while propagating context

type InvokerResponse

type InvokerResponse struct {
	Context  context.Context
	Body     *[]byte
	Header   *http.Header
	Status   int
	Error    error
	Topic    string
	Function string
}

type ResponsePrinter

type ResponsePrinter struct {
	PrintResponseBody bool
}

ResponsePrinter prints function results

func (*ResponsePrinter) Response

func (rp *ResponsePrinter) Response(res InvokerResponse)

Response is triggered by the controller when a message is received from the function invocation

type ResponseSubscriber

type ResponseSubscriber interface {
	// Response is triggered by the controller when a message is
	// received from the function invocation
	Response(InvokerResponse)
}

ResponseSubscriber enables connector or another client in connector to receive results from the function invocation. Note: when implementing this interface, you must not perform any costly or high-latency operations, or should off-load them to another go-routine to prevent blocking.

type TopicMap

type TopicMap struct {
	// contains filtered or unexported fields
}

func NewTopicMap

func NewTopicMap() TopicMap

func (*TopicMap) Match

func (t *TopicMap) Match(topicName string) []string

func (*TopicMap) Sync

func (t *TopicMap) Sync(updated *map[string][]string)

func (*TopicMap) Topics

func (t *TopicMap) Topics() []string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL