functions

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: May 15, 2018 License: Apache-2.0 Imports: 20 Imported by: 41

Documentation

Index

Constants

View Source
const (
	LogsKey        = "logs"
	EventKey       = "event"
	HTTPContextKey = "httpContext"
)

Function context constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context map[string]interface{}

Context provides function context

func (Context) AddLogs added in v0.1.13

func (ctx Context) AddLogs(logs v1.Logs)

AddLogs adds the logs into the context

func (Context) Logs

func (ctx Context) Logs() v1.Logs

Logs returns the logs as a list of strings

func (Context) ReadLogs added in v0.1.13

func (ctx Context) ReadLogs(stderrReader io.Reader, stdoutReader io.Reader)

ReadLogs reads the logs into the context

type DockerImageBuilder added in v0.1.13

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

DockerImageBuilder builds function images

func NewDockerImageBuilder added in v0.1.13

func NewDockerImageBuilder(imageRegistry, registryAuth string, docker *docker.Client) *DockerImageBuilder

NewDockerImageBuilder is the constructor for the DockerImageBuilder

func (*DockerImageBuilder) BuildImage added in v0.1.13

func (ib *DockerImageBuilder) BuildImage(faas, fnID string, exec *Exec) (string, error)

BuildImage packages a function into a docker image. It also adds any FaaS specfic image layers

type Exec

type Exec struct {
	// Code is the function code, either as readable text or base64 encoded (for .zip and .jar archives)
	Code string
	// Main is the function's entry point (aka main function), by default "main"
	Main string
	// Image is the function's docker image
	Image string
	// Name is the function's name
	Name string
}

Exec includes data required to execute a function

type FaaSDriver

type FaaSDriver interface {
	// Create creates (or updates, if is already exists) the function in the FaaS implementation.
	// name is the name of the function.
	// exec defines the function implementation.
	Create(f *Function, exec *Exec) error

	// Delete deletes the function in the FaaS implementation.
	// f is a reference to function defition.
	Delete(f *Function) error

	// GetRunnable returns a callable representation of a function.
	// e is a reference to FunctionExecution.
	GetRunnable(e *FunctionExecution) Runnable
}

FaaSDriver manages Serverless functions and allows to create or delete function, as well as to retrieve runnable representation of the function.

type FnRun

type FnRun struct {
	entitystore.BaseEntity
	FunctionName string                 `json:"functionName"`
	FunctionID   string                 `json:"functionID"`
	FaasID       string                 `json:"faasId"`
	Blocking     bool                   `json:"blocking"`
	Input        interface{}            `json:"input,omitempty"`
	Output       interface{}            `json:"output,omitempty"`
	Secrets      []string               `json:"secrets,omitempty"`
	Services     []string               `json:"services,omitempty"`
	HTTPContext  map[string]interface{} `json:"httpContext,omitempty"`
	Event        *events.CloudEvent     `json:"event,omitempty"`
	Logs         *v1.Logs               `json:"logs,omitempty"`
	FinishedTime time.Time              `json:"finishedTime,omitempty"`

	WaitChan chan struct{} `json:"-"`
}

FnRun struct represents single function run

func (*FnRun) Done

func (r *FnRun) Done()

Done reports completion of function execution

func (*FnRun) Wait

func (r *FnRun) Wait()

Wait waits for function execution to finish

type Function

type Function struct {
	entitystore.BaseEntity
	FaasID    string   `json:"faasId"`
	Code      string   `json:"code"`
	Main      string   `json:"main"`
	ImageName string   `json:"image"`
	Schema    *Schema  `json:"schema,omitempty"`
	Secrets   []string `json:"secrets,omitempty"`
	Services  []string `json:"services,omitempty"`
}

Function struct represents function entity that is stored in entity store

type FunctionError

type FunctionError interface {
	AsFunctionErrorObject() interface{}
}

FunctionError represents error caused by the function

type FunctionExecution

type FunctionExecution struct {
	Context Context
	RunID   string

	FunctionID string
	FaasID     string

	Schemas  *Schemas
	Secrets  []string
	Services []string
	Cookie   string
}

FunctionExecution represents single instance of function execution

type ImageBuilder added in v0.1.13

type ImageBuilder interface {
	// BuildImage builds a function image and pushes it to the docker registry.
	// Returns image full name.
	BuildImage(faas, fnID string, e *Exec) (string, error)
}

ImageBuilder builds a docker image for a serverless function.

type Message added in v0.1.13

type Message struct {
	Context Context     `json:"context"`
	Payload interface{} `json:"payload"`
}

Message contains context and payload for function invocations and events

type Middleware

type Middleware func(f Runnable) Runnable

Middleware allows injecting extra steps for each function execution

type Runnable

type Runnable func(ctx Context, in interface{}) (interface{}, error)

Runnable is a runnable representation of a function

type Runner

type Runner interface {
	Run(fn *FunctionExecution, in interface{}) (interface{}, error)
}

Runner knows how to execute a function

type Schema

type Schema struct {
	In  *spec.Schema `json:"in,omitempty"`
	Out *spec.Schema `json:"out,omitempty"`
}

Schema struct stores input and output validation schemas

type Schemas

type Schemas struct {
	// SchemaIn is the function input validation schema data structure. Can be nil.
	SchemaIn interface{}
	// SchemaOut is the function output validation schema data structure. Can be nil.
	SchemaOut interface{}
}

Schemas represent function validation schemas

type SecretInjector

type SecretInjector interface {
	GetMiddleware(secrets []string, cookie string) Middleware
}

SecretInjector injects secrets into function execution

type ServiceInjector added in v0.1.13

type ServiceInjector interface {
	GetMiddleware(services []string, cookie string) Middleware
}

ServiceInjector injects service bindings into function execution

type UserError

type UserError interface {
	AsUserErrorObject() interface{}
}

UserError represents user error

type Validator

type Validator interface {
	GetMiddleware(schemas *Schemas) Middleware
}

Validator validates function input/output

Directories

Path Synopsis
Package mocks generated by mockery v1.0.0 Package mocks generated by mockery v1.0.0
Package mocks generated by mockery v1.0.0 Package mocks generated by mockery v1.0.0

Jump to

Keyboard shortcuts

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