context

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestModeEnvName                     = "TEST_MODE"
	FunctionContextEnvName              = "FUNC_CONTEXT"
	PodNameEnvName                      = "POD_NAME"
	PodNamespaceEnvName                 = "POD_NAMESPACE"
	ModeEnvName                         = "CONTEXT_MODE"
	Async                  Runtime      = "Async"
	Knative                Runtime      = "Knative"
	OpenFuncBinding        ResourceType = "bindings"
	OpenFuncTopic          ResourceType = "pubsub"
	Success                             = 200
	InternalError                       = 500

	TracingProviderSkywalking    = "skywalking"
	TracingProviderOpentelemetry = "opentelemetry"
	KubernetesMode               = "kubernetes"
	SelfHostMode                 = "self-host"
	TestModeOn                   = "on"
)

Variables

This section is empty.

Functions

func ConvertUserDataToBytes

func ConvertUserDataToBytes(data interface{}) []byte

Types

type Context

type Context interface {
	NativeContext

	// Send provides the ability to allow the user to send data to a specified output target.
	Send(outputName string, data []byte) ([]byte, error)

	// ReturnOnSuccess returns the Out with a success state.
	ReturnOnSuccess() Out

	// ReturnOnInternalError returns the Out with an error state.
	ReturnOnInternalError() Out

	// GetSyncRequest returns the pointer of SyncRequest.
	GetSyncRequest() *SyncRequest

	// GetBindingEvent returns the pointer of common.BindingEvent.
	GetBindingEvent() *common.BindingEvent

	// GetTopicEvent returns the pointer of common.TopicEvent.
	GetTopicEvent() *common.TopicEvent

	// GetCloudEvent returns the pointer of v2.Event.
	GetCloudEvent() *cloudevents.Event

	// GetInnerEvent returns the InnerEvent.
	GetInnerEvent() InnerEvent
}

type EventRequest

type EventRequest struct {
	InputName    string               `json:"inputName,omitempty"`
	BindingEvent *common.BindingEvent `json:"bindingEvent,omitempty"`
	TopicEvent   *common.TopicEvent   `json:"topicEvent,omitempty"`
	CloudEvent   *cloudevents.Event   `json:"cloudEventnt,omitempty"`
	// contains filtered or unexported fields
}

type FunctionContext

type FunctionContext struct {
	Name           string             `json:"name"`
	Version        string             `json:"version"`
	RequestID      string             `json:"requestID,omitempty"`
	Ctx            context.Context    `json:"ctx,omitempty"`
	Inputs         map[string]*Input  `json:"inputs,omitempty"`
	Outputs        map[string]*Output `json:"outputs,omitempty"`
	Runtime        Runtime            `json:"runtime"`
	Port           string             `json:"port,omitempty"`
	State          interface{}        `json:"state,omitempty"`
	Event          *EventRequest      `json:"event,omitempty"`
	SyncRequest    *SyncRequest       `json:"syncRequest,omitempty"`
	PrePlugins     []string           `json:"prePlugins,omitempty"`
	PostPlugins    []string           `json:"postPlugins,omitempty"`
	PluginsTracing *PluginsTracing    `json:"pluginsTracing,omitempty"`
	Out            Out                `json:"out,omitempty"`
	Error          error              `json:"error,omitempty"`
	HttpPattern    string             `json:"httpPattern,omitempty"`
	// contains filtered or unexported fields
}

func (*FunctionContext) DestroyDaprClient

func (ctx *FunctionContext) DestroyDaprClient()

func (*FunctionContext) GetBindingEvent

func (ctx *FunctionContext) GetBindingEvent() *common.BindingEvent

func (*FunctionContext) GetCloudEvent

func (ctx *FunctionContext) GetCloudEvent() *cloudevents.Event

func (*FunctionContext) GetContext

func (ctx *FunctionContext) GetContext() *FunctionContext

func (*FunctionContext) GetError

func (ctx *FunctionContext) GetError() error

func (*FunctionContext) GetHttpPattern

func (ctx *FunctionContext) GetHttpPattern() string

func (*FunctionContext) GetInnerEvent

func (ctx *FunctionContext) GetInnerEvent() InnerEvent

func (*FunctionContext) GetInputs

func (ctx *FunctionContext) GetInputs() map[string]*Input

func (*FunctionContext) GetMode

func (ctx *FunctionContext) GetMode() string

func (*FunctionContext) GetName

func (ctx *FunctionContext) GetName() string

func (*FunctionContext) GetNativeContext

func (ctx *FunctionContext) GetNativeContext() context.Context

func (*FunctionContext) GetOut

func (ctx *FunctionContext) GetOut() Out

func (*FunctionContext) GetOutputs

func (ctx *FunctionContext) GetOutputs() map[string]*Output

func (*FunctionContext) GetPluginsTracingCfg

func (ctx *FunctionContext) GetPluginsTracingCfg() TracingConfig

func (*FunctionContext) GetPodName

func (ctx *FunctionContext) GetPodName() string

func (*FunctionContext) GetPodNamespace

func (ctx *FunctionContext) GetPodNamespace() string

func (*FunctionContext) GetPort

func (ctx *FunctionContext) GetPort() string

func (*FunctionContext) GetPostPlugins

func (ctx *FunctionContext) GetPostPlugins() []string

func (*FunctionContext) GetPrePlugins

func (ctx *FunctionContext) GetPrePlugins() []string

func (*FunctionContext) GetRuntime

func (ctx *FunctionContext) GetRuntime() Runtime

func (*FunctionContext) GetSyncRequest

func (ctx *FunctionContext) GetSyncRequest() *SyncRequest

func (*FunctionContext) GetTopicEvent

func (ctx *FunctionContext) GetTopicEvent() *common.TopicEvent

func (*FunctionContext) HasInputs

func (ctx *FunctionContext) HasInputs() bool

func (*FunctionContext) HasOutputs

func (ctx *FunctionContext) HasOutputs() bool

func (*FunctionContext) InitDaprClientIfNil

func (ctx *FunctionContext) InitDaprClientIfNil()

func (*FunctionContext) ReturnOnInternalError

func (ctx *FunctionContext) ReturnOnInternalError() Out

func (*FunctionContext) ReturnOnSuccess

func (ctx *FunctionContext) ReturnOnSuccess() Out

func (*FunctionContext) Send

func (ctx *FunctionContext) Send(outputName string, data []byte) ([]byte, error)

func (*FunctionContext) SetEvent

func (ctx *FunctionContext) SetEvent(inputName string, event interface{})

func (*FunctionContext) SetNativeContext

func (ctx *FunctionContext) SetNativeContext(c context.Context)

func (*FunctionContext) SetSyncRequest

func (ctx *FunctionContext) SetSyncRequest(w http.ResponseWriter, r *http.Request)

func (*FunctionContext) WithError

func (ctx *FunctionContext) WithError(err error) RuntimeContext

func (*FunctionContext) WithOut

func (ctx *FunctionContext) WithOut(out *FunctionOut) RuntimeContext

type FunctionOut

type FunctionOut struct {
	Code     int               `json:"code"`
	Data     []byte            `json:"data,omitempty"`
	Error    error             `json:"error,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
	// contains filtered or unexported fields
}

func NewFunctionOut

func NewFunctionOut() *FunctionOut

func (*FunctionOut) GetCode

func (o *FunctionOut) GetCode() int

func (*FunctionOut) GetData

func (o *FunctionOut) GetData() []byte

func (*FunctionOut) GetMetadata

func (o *FunctionOut) GetMetadata() map[string]string

func (*FunctionOut) GetOut

func (o *FunctionOut) GetOut() *FunctionOut

func (*FunctionOut) WithCode

func (o *FunctionOut) WithCode(code int) *FunctionOut

func (*FunctionOut) WithData

func (o *FunctionOut) WithData(data []byte) *FunctionOut

type InnerEvent

type InnerEvent interface {

	// SetMetadata sets the metadata in innerEventData.
	SetMetadata(key string, value string)

	// GetMetadata returns the metadata in innerEventData.
	GetMetadata() map[string]string

	// SetUserData sets the userData in innerEventData.
	SetUserData(data interface{})

	// GetUserData returns the userData in innerEventData.
	GetUserData() []byte

	// GetCloudEvent returns the cloudevent object in innerEvent.
	GetCloudEvent() cloudevents.Event

	// MergeMetadata merges the metadata of the incoming event into the new event.
	MergeMetadata(event InnerEvent)

	// Clone clones a new innerEvent.
	Clone(event *cloudevents.Event)

	// GetCloudEventJSON returns the cloudevent in json format.
	GetCloudEventJSON() []byte

	// SetSubject sets the subject of the cloudevent in the innerEvent.
	SetSubject(s string)
}

func NewInnerEvent

func NewInnerEvent(ctx RuntimeContext) InnerEvent

type Input

type Input struct {
	Uri           string            `json:"uri,omitempty"`
	ComponentName string            `json:"componentName"`
	ComponentType string            `json:"componentType"`
	Metadata      map[string]string `json:"metadata,omitempty"`
}

func (*Input) GetType

func (i *Input) GetType() ResourceType

GetType will be called after the context has been parsed correctly, therefore we do not have to handle the error return of getBuildingBlockType()

type NativeContext

type NativeContext interface {
	// GetNativeContext returns the Go native context object.
	GetNativeContext() context.Context

	// SetNativeContext set the Go native context object.
	SetNativeContext(context.Context)
}

type Out

type Out interface {

	// GetOut returns the pointer of raw FunctionOut object.
	GetOut() *FunctionOut

	// GetCode returns the return code in FunctionOut.
	GetCode() int

	// GetData returns the return data in FunctionOut.
	GetData() []byte

	// GetMetadata returns the metadata in FunctionOut.
	GetMetadata() map[string]string

	// WithCode sets the FunctionOut with new return code.
	WithCode(code int) *FunctionOut

	// WithData sets the FunctionOut with new return data.
	WithData(data []byte) *FunctionOut
}

type Output

type Output struct {
	Uri           string            `json:"uri,omitempty"`
	ComponentName string            `json:"componentName"`
	ComponentType string            `json:"componentType"`
	Metadata      map[string]string `json:"metadata,omitempty"`
	Operation     string            `json:"operation,omitempty"`
}

func (*Output) GetType

func (o *Output) GetType() ResourceType

GetType will be called after the context has been parsed correctly, therefore we do not have to handle the error return of getBuildingBlockType()

type PluginsTracing

type PluginsTracing struct {
	Enabled  bool              `json:"enabled" yaml:"enabled"`
	Provider *TracingProvider  `json:"provider" yaml:"provider"`
	Tags     map[string]string `json:"tags,omitempty" yaml:"tags,omitempty"`
	Baggage  map[string]string `json:"baggage" yaml:"baggage"`
}

func (*PluginsTracing) GetBaggage

func (tracing *PluginsTracing) GetBaggage() map[string]string

func (*PluginsTracing) GetTags

func (tracing *PluginsTracing) GetTags() map[string]string

func (*PluginsTracing) IsEnabled

func (tracing *PluginsTracing) IsEnabled() bool

func (*PluginsTracing) ProviderName

func (tracing *PluginsTracing) ProviderName() string

func (*PluginsTracing) ProviderOapServer

func (tracing *PluginsTracing) ProviderOapServer() string

type ResourceType

type ResourceType string

type ResponseWriterWrapper

type ResponseWriterWrapper struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponseWriterWrapper

func NewResponseWriterWrapper(w http.ResponseWriter, statusCode int) *ResponseWriterWrapper

func (*ResponseWriterWrapper) Header

func (rww *ResponseWriterWrapper) Header() http.Header

func (*ResponseWriterWrapper) Status

func (rww *ResponseWriterWrapper) Status() int

func (*ResponseWriterWrapper) Write

func (rww *ResponseWriterWrapper) Write(bytes []byte) (int, error)

func (*ResponseWriterWrapper) WriteHeader

func (rww *ResponseWriterWrapper) WriteHeader(statusCode int)

type Runtime

type Runtime string

type RuntimeContext

type RuntimeContext interface {
	NativeContext

	// GetName returns the function's name.
	GetName() string

	// GetMode returns the operating environment mode of the function.
	GetMode() string

	// GetContext returns the pointer of raw OpenFunction FunctionContext object.
	GetContext() *FunctionContext

	// GetOut returns the pointer of raw OpenFunction FunctionOut object.
	GetOut() Out

	// HasInputs detects if the function has any input sources.
	HasInputs() bool

	// HasOutputs detects if the function has any output targets.
	HasOutputs() bool

	// InitDaprClientIfNil detects whether the dapr client in the current FunctionContext has been initialized,
	// and initializes it if it has not been initialized.
	InitDaprClientIfNil()

	// DestroyDaprClient destroys the dapr client when the function is executed with an exception.
	DestroyDaprClient()

	// GetPrePlugins returns a list of plugin names for the previous phase of function execution.
	GetPrePlugins() []string

	// GetPostPlugins returns a list of plugin names for the post phase of function execution.
	GetPostPlugins() []string

	// GetRuntime returns the Runtime.
	GetRuntime() Runtime

	// GetPort returns the port that the function service is listening on.
	GetPort() string

	// GetError returns the error status of the function.
	GetError() error

	// GetHttpPattern returns the path of the server listening in Knative runtime mode.
	GetHttpPattern() string

	// SetSyncRequest sets the native http.ResponseWriter and *http.Request when an http request is received.
	SetSyncRequest(w http.ResponseWriter, r *http.Request)

	// SetEvent sets the name of the input source and the native event when an event request is received.
	SetEvent(inputName string, event interface{})

	// GetInputs returns the mapping relationship of *Input.
	GetInputs() map[string]*Input

	// GetOutputs returns the mapping relationship of *Output.
	GetOutputs() map[string]*Output

	// GetSyncRequest returns the pointer of SyncRequest.
	GetSyncRequest() *SyncRequest

	// GetBindingEvent returns the pointer of common.BindingEvent.
	GetBindingEvent() *common.BindingEvent

	// GetTopicEvent returns the pointer of common.TopicEvent.
	GetTopicEvent() *common.TopicEvent

	// GetCloudEvent returns the pointer of v2.Event.
	GetCloudEvent() *cloudevents.Event

	// GetInnerEvent returns the InnerEvent.
	GetInnerEvent() InnerEvent

	// WithOut adds the FunctionOut object to the RuntimeContext.
	WithOut(out *FunctionOut) RuntimeContext

	// WithError adds the error state to the RuntimeContext.
	WithError(err error) RuntimeContext

	// GetPodName returns the name of the pod the function is running on.
	GetPodName() string

	// GetPodNamespace returns the namespace of the pod the function is running on.
	GetPodNamespace() string

	// GetPluginsTracingCfg returns the TracingConfig interface.
	GetPluginsTracingCfg() TracingConfig
}

func GetRuntimeContext

func GetRuntimeContext() (RuntimeContext, error)

type SyncRequest

type SyncRequest struct {
	ResponseWriter http.ResponseWriter `json:"responseWriter,omitempty"`
	Request        *http.Request       `json:"request,omitempty"`
}

type TracingConfig

type TracingConfig interface {

	// IsEnabled detects if the tracing configuration is enabled.
	IsEnabled() bool

	// ProviderName returns the name of tracing provider.
	ProviderName() string

	// ProviderOapServer returns the oap server of the tracing provider.
	ProviderOapServer() string

	// GetTags returns the tags of the tracing configuration.
	GetTags() map[string]string

	// GetBaggage returns the baggage of the tracing configuration.
	GetBaggage() map[string]string
}

type TracingProvider

type TracingProvider struct {
	Name      string `json:"name" yaml:"name"`
	OapServer string `json:"oapServer" yaml:"oapServer"`
}

Jump to

Keyboard shortcuts

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