types

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

ControllerConfig configures a connector SDK controller

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCredentials

func GetCredentials() *sdk.BasicAuth

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, headers http.Header, opts ...InvokeOptionFunc)
	InvokeWithContext(ctx context.Context, topic string, message *[]byte, headers http.Header, opts ...InvokeOptionFunc)
	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 sdk.ClientAuth, config *ControllerConfig) Controller

NewController create a new connector SDK controller

type ControllerConfig

type ControllerConfig struct {
	// UpstreamTimeout controls maximum timeout for a function invocation, which is done via the gateway
	UpstreamTimeout time.Duration

	// GatewayURL is the remote OpenFaaS gateway
	GatewayURL string

	// PrintResponse if true prints the function responses
	PrintResponse bool

	// PrintResponseBody prints the function's response body to stdout
	PrintResponseBody bool

	// PrintRequestBody prints the request's body to stdout.
	PrintRequestBody 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

	// AsyncFunctionCallbackURL defines the callback URL for asynchronous invocations
	AsyncFunctionCallbackURL string

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

	// ContentType defines which content type will be set in the header to invoke the function. i.e "application/json".
	// Optional, if not set the Content-Type header will not be set.
	ContentType string

	// BasicAuth whether basic auth is enabled or disabled
	BasicAuth bool

	// UserAgent defines the user agent to be used in the request to invoke the function, it should be of the format:
	// company/NAME-connector
	UserAgent string

	// Namespace defines the namespace of the functions to be mapped and invoked. If empty, all namespaces will be used.
	Namespace string

	// SendTopic defines whether the topic will be sent in the invocation request using the header 'X-Topic'.
	SendTopic bool

	// TopicMatcher overrides how the topic received is matched against the mapped functions. Defaults to an equality check.
	TopicMatcher MatchTopicFunc
}

type FunctionLookupBuilder

type FunctionLookupBuilder struct {
	GatewayURL     string
	Client         *http.Client
	Credentials    *auth.BasicAuthCredentials
	TopicDelimiter string
	Namespace      string
	// contains filtered or unexported fields
}

FunctionLookupBuilder builds a list of OpenFaaS functions

func NewFunctionLookupBuilder added in v0.2.0

func NewFunctionLookupBuilder(gatewayURL, topicDelimiter string, client *http.Client, credentials sdk.ClientAuth, namespace string) *FunctionLookupBuilder

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 InvokeOptionFunc added in v0.2.0

type InvokeOptionFunc func(*InvokeOptions)

InvokeOptionFunc defines a function that modifies an InvokeOptions instance.

func WithInvokeAsyncCallbackURL added in v0.2.0

func WithInvokeAsyncCallbackURL(callbackURL string) InvokeOptionFunc

WithInvokeAsyncCallbackURL sets the callback URL used when invoking a function asynchronously. It will override the callback URL set in the InvokerOptions.

func WithInvokeContentType added in v0.2.0

func WithInvokeContentType(contentType string) InvokeOptionFunc

WithInvokeContentType sets the content type to be set in the header of invocation requests. It will override Invoker.ContentType.

func WithInvokeTopic added in v0.2.0

func WithInvokeTopic(topic string) InvokeOptionFunc

WithInvokeTopic sets the topic of the message used for invoking a function.

type InvokeOptions added in v0.2.0

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

InvokeOptions defines additional configuration options for the invocation of a function using Invoker.Invoke.

type Invoker

type Invoker struct {
	PrintResponse bool
	PrintRequest  bool
	Client        *http.Client
	GatewayURL    string
	ContentType   string
	Responses     chan InvokerResponse
	// contains filtered or unexported fields
}

Invoker is used to send requests to functions. Responses are returned via the Responses channel.

func NewInvoker

func NewInvoker(gatewayURL string, client *http.Client, contentType string, printResponse, printRequest bool, opts ...InvokerOptionFunc) *Invoker

NewInvoker constructs an Invoker instance

func (*Invoker) Invoke

func (i *Invoker) Invoke(ctx context.Context, functionName string, message *[]byte, headers http.Header, opts ...InvokeOptionFunc) InvokerResponse

Invoke triggers the given function by accessing the API Gateway. functionName must include the namespace (e.g. "my-function.my-namespace").

func (*Invoker) InvokeWithTopic added in v0.2.0

func (i *Invoker) InvokeWithTopic(ctx context.Context, topicMap *TopicMap, topic string, message *[]byte, headers http.Header, opts ...InvokeOptionFunc)

InvokeWithTopic triggers a function using a topic by accessing the API Gateway.

type InvokerOptionFunc added in v0.2.0

type InvokerOptionFunc func(*InvokerOptions)

InvokerOptionFunc defines a function that modifies an InvokerOptions instance.

func WithInvokerAsyncCallbackURL added in v0.2.0

func WithInvokerAsyncCallbackURL(callbackURL string) InvokerOptionFunc

WithInvokerAsyncCallbackURL sets the callback URL used when invoking a function asynchronously.

func WithInvokerSendTopic added in v0.2.0

func WithInvokerSendTopic(sendTopic bool) InvokerOptionFunc

WithInvokerSendTopic sets whether the topic of the message used for invoking a function has to be sent in the "X-Topic" header of the request.

func WithInvokerUserAgent added in v0.2.0

func WithInvokerUserAgent(userAgent string) InvokerOptionFunc

WithInvokerUserAgent sets the user agent to be used in the invocation requests.

type InvokerOptions added in v0.2.0

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

InvokerOptions defines additional configuration options for an Invoker.

type InvokerResponse

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

InvokerResponse is a wrapper to contain the response or error the Invoker receives from the function. Networking errors wil be found in the Error field.

type MatchTopicFunc

type MatchTopicFunc func(topicReceived, topicFunction string) bool

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(matchFunc MatchTopicFunc) *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