types

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: MIT Imports: 15 Imported by: 8

Documentation

Overview

ControllerConfig configures a connector SDK controller

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, headers http.Header)
	InvokeWithContext(ctx context.Context, topic string, message *[]byte, headers http.Header)
	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(auth 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

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

	// ContentType defines which content type will be set in the header to inkoke 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
}

type FunctionLookupBuilder

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

FunctionLookupBuilder builds a list of OpenFaaS functions

func NewFunctionLookupBuilder added in v0.7.1

func NewFunctionLookupBuilder(gatewayURL, topicDelimiter string, client *http.Client, auth sdk.ClientAuth) *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 Invoker

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

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, userAgent string) *Invoker

NewInvoker constructs an Invoker instance

func (*Invoker) Invoke

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

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, headers http.Header)

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
	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 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