handler

package module
v0.0.0-...-b31e65b Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2020 License: MIT Imports: 2 Imported by: 28

README

go-function-sdk

An SDK for building OpenFaaS functions in Go

Installing

Use go get to retrieve the SDK to add it to your GOPATH workspace, or project's Go module dependencies.

go get github.com/openfaas-incubator/go-function-sdk

To update the SDK use go get -u to retrieve the latest version of the SDK.

go get -u github.com/openfaas-incubator/go-function-sdk

Features

Handler definition
type FunctionHandler interface {
	Handle(req Request) (Response, error)
}

FunctionHandler interface is used by golang-http template to define a functions handler

Secrets

For the time being please use the secrets function from github.com/openfaas/openfaas-cloud/sdk

See: https://github.com/openfaas/openfaas-cloud/blob/master/sdk/secrets.go

Usage:

secret, err := sdk.ReadSecret("MY_SECRET")
if err != nil {
    return fmt.Errorf("error reading secret. %v", err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FunctionHandler

type FunctionHandler interface {
	Handle(req Request) (Response, error)
}

FunctionHandler used for a serverless Go method invocation

type Request

type Request struct {
	Body        []byte
	Header      http.Header
	QueryString string
	Method      string
	Host        string
	// contains filtered or unexported fields
}

Request of function call

func (*Request) Context

func (r *Request) Context() context.Context

Context is set for optional cancellation inflight requests.

func (*Request) WithContext

func (r *Request) WithContext(ctx context.Context)

WithContext overides the context for the Request struct

type Response

type Response struct {

	// Body the body will be written back
	Body []byte

	// StatusCode needs to be populated with value such as http.StatusOK
	StatusCode int

	// Header is optional and contains any additional headers the function response should set
	Header http.Header
}

Response of function call

Jump to

Keyboard shortcuts

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