sdk

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

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

Go to latest
Published: Oct 18, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Adapted from https://github.com/openfaas/templates-sdk/blob/master/go-http/handler.go Original license: MIT

Index

Constants

View Source
const (
	ErrCodeUnspecified errorCode = iota
	ErrCodeExecuteAgain
	ErrCodeFailed
	ErrCodeTransient
)
View Source
const (
	ActivityIDHeader         = "X-Activity-ID"
	EnvironmentIDHeader      = "X-Environment-ID"
	EnvironmentNameHeader    = "X-Environment-Name"
	WorkflowTokenHeader      = "X-Workflow-Token"
	EngineAPIEndpointHeader  = "X-Engine-Endpoint"
	ActivityFileUploadHeader = "X-Activity-File-Upload"
)

Variables

View Source
var WithLogReqTimeout = func(reqTimeout time.Duration) WriterOption {
	return func(w *writer) {
		w.reqTimeout = reqTimeout
	}
}
View Source
var WithSkipTLSVerify = func(skipTLSVerify bool) WriterOption {
	return func(w *writer) {
		w.skipTLSVerify = skipTLSVerify
	}
}
View Source
var WithWriteFlushTickRate = func(tickRate time.Duration) WriterOption {
	return func(w *writer) {
		w.flushTickRate = tickRate
	}
}

Functions

func IsErrExecuteAgain

func IsErrExecuteAgain(err error) bool

func IsErrFailed

func IsErrFailed(err error) bool

func IsErrFunction

func IsErrFunction(err error) bool

func IsErrTransient

func IsErrTransient(err error) bool

func NewActivityLogWriter

func NewActivityLogWriter(ctx context.Context, logger *slog.Logger, url, token string, opts ...WriterOption) io.WriteCloser

func NewErrExecuteAgain

func NewErrExecuteAgain(msg string, data map[string]any) error

func NewErrFailed

func NewErrFailed(msg string) error

func NewErrTransient

func NewErrTransient(msg string) error

Types

type ErrFunction

type ErrFunction struct {
	ErrCode    errorCode      `json:"error_code"`
	Message    string         `json:"message"`
	StackTrace []stackFrame   `json:"stack_trace"`
	Data       map[string]any `json:"data"`
}

func AsErrFunction

func AsErrFunction(err error) (*ErrFunction, bool)

func (*ErrFunction) Error

func (e *ErrFunction) Error() string

type FunctionHandler

type FunctionHandler interface {
	Handle(ctx context.Context, logger Logger, req Request) (Response, error)
}

FunctionHandler used for a serverless Go method invocation

type FunctionSDK

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

func NewFunctionSDK

func NewFunctionSDK(opts ...SDKOption) (*FunctionSDK, error)

func (*FunctionSDK) Run

func (fsdk *FunctionSDK) Run(ctx context.Context) error

type Handler

type Handler func(ctx context.Context, logger Logger, req Request) (Response, error)

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
	Log(ctx context.Context, level slog.Level, msg string, args ...any)
}

type Object

type Object map[string]any

func (Object) GetAsString

func (r Object) GetAsString(key string) (string, bool)

func (Object) GetBool

func (r Object) GetBool(keys ...string) (bool, error)

func (Object) GetFloat64

func (r Object) GetFloat64(keys ...string) (float64, error)

func (Object) GetInt

func (r Object) GetInt(keys ...string) (int, error)

func (Object) GetInt64

func (r Object) GetInt64(keys ...string) (int64, error)

func (Object) GetSlice

func (r Object) GetSlice(keys ...string) ([]interface{}, error)

func (Object) GetString

func (r Object) GetString(keys ...string) (string, error)

func (Object) GetStringMap

func (r Object) GetStringMap(keys ...string) (Object, error)

type ReadyResponse

type ReadyResponse struct {
	Ready          bool  `json:"ready"`
	NumConnections int32 `json:"num_connections"`
}

type Request

type Request = Object

type Response

type Response = Object

type SDKOption

type SDKOption func(*SDKOptions)

func WithHandler

func WithHandler(handler Handler) SDKOption

func WithHealthInterval

func WithHealthInterval(healthInterval time.Duration) SDKOption

func WithListener

func WithListener(listener net.Listener) SDKOption

func WithLogFlushRate

func WithLogFlushRate(logFlushRate time.Duration) SDKOption

func WithLogLevel

func WithLogLevel(logLevel slog.Level) SDKOption

func WithLogUploadRetryCount

func WithLogUploadRetryCount(logUploadRetryCount int) SDKOption

func WithLogWriteTimeout

func WithLogWriteTimeout(logWriteTimeout time.Duration) SDKOption

func WithPort

func WithPort(port int) SDKOption

func WithReadTimeout

func WithReadTimeout(readTimeout time.Duration) SDKOption

func WithServerSkipTLSVerify

func WithServerSkipTLSVerify(skipTLSVerify bool) SDKOption

func WithShutdownTimeout

func WithShutdownTimeout(shutdownTimeout time.Duration) SDKOption

func WithWriteTimeout

func WithWriteTimeout(writeTimeout time.Duration) SDKOption

type SDKOptions

type SDKOptions struct {
	Port                int
	Listener            net.Listener
	Handler             Handler
	ReadTimeout         time.Duration
	WriteTimeout        time.Duration
	ShutdownTimeout     time.Duration
	HealthInterval      time.Duration
	LogLevel            slog.Level
	LogUploadRetryCount int
	LogFlushRate        time.Duration
	LogWriteTimeout     time.Duration
	SkipTLSVerify       bool
}

type WriterOption

type WriterOption func(*writer)

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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