workers

package
v1.14.2 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package workers contains a base class that is used by components that are based on Cloudflare Workers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

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

Base is a base class for components that rely on Cloudflare Base

func (Base) Client

func (w Base) Client() *http.Client

Client returns the HTTP client.

func (*Base) Close

func (w *Base) Close() error

Close the base component.

func (*Base) Init

func (w *Base) Init(workerBindings []CFBinding, componentDocsURL string, infoResponseValidate func(*InfoEndpointResponse) error) (err error)

Init the base class.

func (*Base) SetLogger

func (w *Base) SetLogger(logger logger.Logger)

SetLogger sets the logger object.

func (*Base) SetMetadata

func (w *Base) SetMetadata(metadata *BaseMetadata)

SetMetadata sets the metadata for the base object.

type BaseMetadata

type BaseMetadata struct {
	WorkerURL        string `mapstructure:"workerUrl"`
	CfAPIToken       string `mapstructure:"cfAPIToken"`
	CfAccountID      string `mapstructure:"cfAccountID"`
	Key              string `mapstructure:"key"`
	WorkerName       string `mapstructure:"workerName"`
	TimeoutInSeconds string `mapstructure:"timeoutInSeconds"`

	Timeout time.Duration `mapstructure:"-"`
	// contains filtered or unexported fields
}

Base metadata struct, common to all components The components can be initialized in two ways: - Instantiate the component with a "workerURL": assumes a worker that has been pre-deployed and it's ready to be used; we will not need API tokens - Instantiate the component with a "cfAPIToken" and "cfAccountID": Dapr will take care of creating the worker if it doesn't exist (or upgrade it if needed)

func (BaseMetadata) CreateToken

func (m BaseMetadata) CreateToken() (string, error)

CreateToken creates a JWT token for authorizing requests

func (*BaseMetadata) Validate

func (m *BaseMetadata) Validate() error

Validate the metadata object.

type CFBinding

type CFBinding struct {
	Name string `json:"name"`
	Type string `json:"type"`
	// For variables
	Text *string `json:"text,omitempty"`
	// For KV namespaces
	KVNamespaceID *string `json:"namespace_id,omitempty"`
	// For queues
	QueueName *string `json:"queue_name,omitempty"`
}

CFBinding contains a Cloudflare binding that is attached to the worker

type InfoEndpointResponse

type InfoEndpointResponse struct {
	Version string   `json:"version"`
	Queues  []string `json:"queues"`
	KV      []string `json:"kv"`
}

Object containing the response from the info endpoint

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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