Documentation
¶
Overview ¶
Package sdk Adapted from https://github.com/openfaas/templates-sdk/blob/master/go-http/handler.go Original license: MIT
Index ¶
- Constants
- Variables
- func IsErrConflict(err error) bool
- func IsErrExecuteAgain(err error) bool
- func IsErrFailed(err error) bool
- func IsErrFunction(err error) bool
- func IsErrNotFound(err error) bool
- func IsErrTransient(err error) bool
- func NewActivityLogWriter(ctx context.Context, logger *slog.Logger, url, token string, ...) io.WriteCloser
- func NewErrConflict(msg string) error
- func NewErrExecuteAgain(msg string, data map[string]any) error
- func NewErrFailed(msg string) error
- func NewErrNotFound(msg string) error
- func NewErrTransient(msg string) error
- type ErrFunction
- type EventDetails
- func (e EventDetails) GetActionName() (string, bool)
- func (e EventDetails) GetSchedulesName() (string, bool)
- func (e EventDetails) GetTypeAsString() string
- func (e EventDetails) GetWorkloadName() (string, bool)
- func (e EventDetails) IsAction() bool
- func (e EventDetails) IsDeploy() bool
- func (e EventDetails) IsDestroy() bool
- func (e EventDetails) IsEnvironmentDeploy() bool
- func (e EventDetails) IsEnvironmentDestroy() bool
- func (e EventDetails) IsForceDestroy() bool
- func (e EventDetails) IsSchedules() bool
- func (e EventDetails) IsWorkload() bool
- func (e EventDetails) IsWorkloadDeploy() bool
- func (e EventDetails) IsWorkloadDestroy() bool
- type EventType
- type FunctionHandler
- type FunctionSDK
- type Handler
- type Logger
- type Object
- func (r Object) GetAsString(key string) (string, bool)
- func (r Object) GetBool(keys ...string) (bool, error)
- func (r Object) GetFloat64(keys ...string) (float64, error)
- func (r Object) GetInt(keys ...string) (int, error)
- func (r Object) GetInt64(keys ...string) (int64, error)
- func (r Object) GetSlice(keys ...string) ([]interface{}, error)
- func (r Object) GetString(keys ...string) (string, error)
- func (r Object) GetStringMap(keys ...string) (Object, error)
- func (r Object) MetaString(key string) string
- type ReadyResponse
- type Request
- type Response
- type SDKOption
- func WithHandler(handler Handler) SDKOption
- func WithHealthInterval(healthInterval time.Duration) SDKOption
- func WithListener(listener net.Listener) SDKOption
- func WithLogFlushRate(logFlushRate time.Duration) SDKOption
- func WithLogLevel(logLevel slog.Level) SDKOption
- func WithLogUploadRetryCount(logUploadRetryCount int) SDKOption
- func WithLogWriteTimeout(logWriteTimeout time.Duration) SDKOption
- func WithPort(port int) SDKOption
- func WithReadTimeout(readTimeout time.Duration) SDKOption
- func WithServerSkipTLSVerify(skipTLSVerify bool) SDKOption
- func WithShutdownTimeout(shutdownTimeout time.Duration) SDKOption
- func WithWriteTimeout(writeTimeout time.Duration) SDKOption
- type SDKOptions
- type WriterOption
Constants ¶
const ( ErrCodeUnspecified errorCode = iota ErrCodeExecuteAgain ErrCodeFailed ErrCodeTransient ErrCodeNotFound ErrCodeConflict )
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" OrganizationIDHeader = "X-Organization-ID" ProjectIDHeader = "X-Project-ID" EaasStateEndpointHeader = "X-Eaas-State-Endpoint" EaasStateAPITokenHeader = "X-Eaas-State-Token" EventSourceHeader = "X-Event-Source" EventSourceNameHeader = "X-Event-Source-Name" EventTypeHeader = "X-Event-Type" )
Variables ¶
var WithLogReqTimeout = func(reqTimeout time.Duration) WriterOption {
return func(w *writer) {
w.reqTimeout = reqTimeout
}
}
var WithSkipTLSVerify = func(skipTLSVerify bool) WriterOption {
return func(w *writer) {
w.skipTLSVerify = skipTLSVerify
}
}
var WithWriteFlushTickRate = func(tickRate time.Duration) WriterOption {
return func(w *writer) {
w.flushTickRate = tickRate
}
}
Functions ¶
func IsErrConflict ¶
func IsErrExecuteAgain ¶
func IsErrFailed ¶
func IsErrFunction ¶
func IsErrNotFound ¶
func IsErrTransient ¶
func NewActivityLogWriter ¶
func NewActivityLogWriter(ctx context.Context, logger *slog.Logger, url, token string, opts ...WriterOption) io.WriteCloser
func NewErrConflict ¶
func NewErrFailed ¶
func NewErrNotFound ¶
func NewErrTransient ¶
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 EventDetails ¶
EventDetails represents metadata about an event, including its source, source name, and type.
func NewEventDetails ¶
func NewEventDetails(request Request) *EventDetails
NewEventDetails creates a new EventDetails instance by extracting metadata fields from the given Request object. The request's metadata is used to populate the EventDetails's Source, SourceName, and Type fields.
func (EventDetails) GetActionName ¶
func (e EventDetails) GetActionName() (string, bool)
GetActionName returns the SourceName and true if the event Source is "action"; otherwise returns an empty string and false.
func (EventDetails) GetSchedulesName ¶
func (e EventDetails) GetSchedulesName() (string, bool)
GetSchedulesName returns the SourceName and true if the event Source is "schedules"; otherwise, returns an empty string and false.
func (EventDetails) GetTypeAsString ¶
func (e EventDetails) GetTypeAsString() string
GetTypeAsString converts the EventDetails's Type field to a string and returns it.
func (EventDetails) GetWorkloadName ¶
func (e EventDetails) GetWorkloadName() (string, bool)
GetWorkloadName returns the SourceName and true if the event Source is "workload"; otherwise, returns an empty string and false.
func (EventDetails) IsAction ¶
func (e EventDetails) IsAction() bool
IsAction determines if the event's Source is set to "action".
func (EventDetails) IsDeploy ¶
func (e EventDetails) IsDeploy() bool
IsDeploy checks if the event's Type is DeployEventType.
func (EventDetails) IsDestroy ¶
func (e EventDetails) IsDestroy() bool
IsDestroy checks if the event's Type is set to DestroyEventType or ForceDestroyEventType.
func (EventDetails) IsEnvironmentDeploy ¶
func (e EventDetails) IsEnvironmentDeploy() bool
IsEnvironmentDeploy checks if the event's Source is "environment" and its Type is DeployEventType.
func (EventDetails) IsEnvironmentDestroy ¶
func (e EventDetails) IsEnvironmentDestroy() bool
IsEnvironmentDestroy checks if the event's Source is "environment" and its Type is DestroyEventType or ForceDestroyEventType.
func (EventDetails) IsForceDestroy ¶
func (e EventDetails) IsForceDestroy() bool
IsForceDestroy checks if the event's Type is set to ForceDestroyEventType.
func (EventDetails) IsSchedules ¶
func (e EventDetails) IsSchedules() bool
IsSchedules determines if the event's Source is set to "schedules".
func (EventDetails) IsWorkload ¶
func (e EventDetails) IsWorkload() bool
IsWorkload checks if the event's Source is set to "workload".
func (EventDetails) IsWorkloadDeploy ¶
func (e EventDetails) IsWorkloadDeploy() bool
IsWorkloadDeploy checks if the event's Source is "workload" and its Type is DeployEventType.
func (EventDetails) IsWorkloadDestroy ¶
func (e EventDetails) IsWorkloadDestroy() bool
IsWorkloadDestroy returns true if the event's Source is "environment" and its Type indicates a destroy operation.
type EventType ¶
type EventType string
EventType represents the type of event, commonly used in event-driven systems for categorization or processing.
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)
type Object ¶
func (Object) MetaString ¶
type ReadyResponse ¶
type SDKOption ¶
type SDKOption func(*SDKOptions)
func WithHandler ¶
func WithHealthInterval ¶
func WithListener ¶
func WithLogFlushRate ¶
func WithLogLevel ¶
func WithLogUploadRetryCount ¶
func WithLogWriteTimeout ¶
func WithReadTimeout ¶
func WithServerSkipTLSVerify ¶
func WithShutdownTimeout ¶
func WithWriteTimeout ¶
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)