Documentation ¶
Index ¶
- func CreateContext() context.Context
- func GetBinding(ctx context.Context, name string) js.Value
- func Getenv(ctx context.Context, name string) string
- func PassThroughOnException(ctx context.Context)
- func WaitUntil(ctx context.Context, task func())
- type DurableObjectId
- type DurableObjectNamespace
- type DurableObjectStub
- type KVNamespace
- func (kv *KVNamespace) Delete(key string) error
- func (kv *KVNamespace) GetReader(key string, opts *KVNamespaceGetOptions) (io.Reader, error)
- func (kv *KVNamespace) GetString(key string, opts *KVNamespaceGetOptions) (string, error)
- func (kv *KVNamespace) List(opts *KVNamespaceListOptions) (*KVNamespaceListResult, error)
- func (kv *KVNamespace) PutReader(key string, value io.Reader, opts *KVNamespacePutOptions) error
- func (kv *KVNamespace) PutString(key string, value string, opts *KVNamespacePutOptions) error
- type KVNamespaceGetOptions
- type KVNamespaceListKey
- type KVNamespaceListOptions
- type KVNamespaceListResult
- type KVNamespacePutOptions
- type R2Bucket
- type R2HTTPMetadata
- type R2Object
- type R2Objects
- type R2PutOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateContext ¶
func GetBinding ¶
GetBinding gets a value of an environment binding.
- https://developers.cloudflare.com/workers/platform/bindings/about-service-bindings/
- This function panics when a runtime context is not found.
func Getenv ¶
Getenv gets a value of an environment variable.
- https://developers.cloudflare.com/workers/platform/environment-variables/
- This function panics when a runtime context is not found.
func PassThroughOnException ¶
PassThroughOnException prevents a runtime error response when the Worker script throws an unhandled exception. Instead, the request forwards to the origin server as if it had not gone through the worker. see: https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#passthroughonexception
func WaitUntil ¶
WaitUntil extends the lifetime of the "fetch" event. It accepts an asynchronous task which the Workers runtime will execute before the handler terminates but without blocking the response. see: https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#waituntil
Types ¶
type DurableObjectId ¶
type DurableObjectId struct {
// contains filtered or unexported fields
}
DurableObjectId represents an identifier for a durable object.
type DurableObjectNamespace ¶
type DurableObjectNamespace struct {
// contains filtered or unexported fields
}
DurableObjectNamespace represents the namespace of the durable object.
func NewDurableObjectNamespace ¶
func NewDurableObjectNamespace(ctx context.Context, varName string) (*DurableObjectNamespace, error)
NewDurableObjectNamespace returns the namespace for the `varName` binding.
This binding must be defined in the `wrangler.toml` file. The method will return an `error` when there is no binding defined by `varName`.
func (*DurableObjectNamespace) Get ¶
func (ns *DurableObjectNamespace) Get(id *DurableObjectId) (*DurableObjectStub, error)
Get obtains the durable object stub for `id`.
https://developers.cloudflare.com/workers/runtime-apis/durable-objects/#obtaining-an-object-stub
func (*DurableObjectNamespace) IdFromName ¶
func (ns *DurableObjectNamespace) IdFromName(name string) *DurableObjectId
IdFromName returns a `DurableObjectId` for the given `name`.
https://developers.cloudflare.com/workers/runtime-apis/durable-objects/#deriving-ids-from-names
type DurableObjectStub ¶
type DurableObjectStub struct {
// contains filtered or unexported fields
}
DurableObjectStub represents the stub to communicate with the durable object.
func (*DurableObjectStub) Fetch ¶
Fetch calls the durable objects `fetch()` method.
https://developers.cloudflare.com/workers/runtime-apis/durable-objects/#sending-http-requests
type KVNamespace ¶
type KVNamespace struct {
// contains filtered or unexported fields
}
KVNamespace represents interface of Cloudflare Worker's KV namespace instance.
- https://developers.cloudflare.com/workers/runtime-apis/kv/
- https://github.com/cloudflare/workers-types/blob/3012f263fb1239825e5f0061b267c8650d01b717/index.d.ts#L850
func NewKVNamespace ¶
func NewKVNamespace(ctx context.Context, varName string) (*KVNamespace, error)
NewKVNamespace returns KVNamespace for given variable name.
- variable name must be defined in wrangler.toml as kv_namespace's binding.
- if the given variable name doesn't exist on runtime context, returns error.
- This function panics when a runtime context is not found.
func (*KVNamespace) Delete ¶
func (kv *KVNamespace) Delete(key string) error
Delete deletes key-value pair specified by the key.
- if a network error happens, returns error.
func (*KVNamespace) GetReader ¶
func (kv *KVNamespace) GetReader(key string, opts *KVNamespaceGetOptions) (io.Reader, error)
GetReader gets stream value by the specified key.
- if a network error happens, returns error.
func (*KVNamespace) GetString ¶
func (kv *KVNamespace) GetString(key string, opts *KVNamespaceGetOptions) (string, error)
GetString gets string value by the specified key.
- if a network error happens, returns error.
func (*KVNamespace) List ¶
func (kv *KVNamespace) List(opts *KVNamespaceListOptions) (*KVNamespaceListResult, error)
List lists keys stored into the KV namespace.
func (*KVNamespace) PutReader ¶
func (kv *KVNamespace) PutReader(key string, value io.Reader, opts *KVNamespacePutOptions) error
PutReader puts stream value into KV with key.
- This method copies all bytes into memory for implementation restriction.
- if a network error happens, returns error.
func (*KVNamespace) PutString ¶
func (kv *KVNamespace) PutString(key string, value string, opts *KVNamespacePutOptions) error
PutString puts string value into KV with key.
- if a network error happens, returns error.
type KVNamespaceGetOptions ¶
type KVNamespaceGetOptions struct {
CacheTTL int
}
KVNamespaceGetOptions represents Cloudflare KV namespace get options.
type KVNamespaceListKey ¶
type KVNamespaceListKey struct { Name string // Expiration is an expiration of KV value cache. The value `0` means no expiration. Expiration int }
KVNamespaceListKey represents Cloudflare KV namespace list key.
type KVNamespaceListOptions ¶
KVNamespaceListOptions represents Cloudflare KV namespace list options.
type KVNamespaceListResult ¶
type KVNamespaceListResult struct { Keys []*KVNamespaceListKey ListComplete bool Cursor string }
KVNamespaceListResult represents Cloudflare KV namespace list result.
type KVNamespacePutOptions ¶
KVNamespacePutOptions represents Cloudflare KV namespace put options.
type R2Bucket ¶
type R2Bucket struct {
// contains filtered or unexported fields
}
R2Bucket represents interface of Cloudflare Worker's R2 Bucket instance.
- https://developers.cloudflare.com/r2/runtime-apis/#bucket-method-definitions
- https://github.com/cloudflare/workers-types/blob/3012f263fb1239825e5f0061b267c8650d01b717/index.d.ts#L1006
func NewR2Bucket ¶
NewR2Bucket returns R2Bucket for given variable name.
- variable name must be defined in wrangler.toml.
- see example: https://github.com/tinyredglasses/workers/tree/main/_examples/r2-image-viewer
- if the given variable name doesn't exist on runtime context, returns error.
- This function panics when a runtime context is not found.
func (*R2Bucket) Delete ¶
Delete returns the result of `delete` call to R2Bucket.
- if a network error happens, returns error.
func (*R2Bucket) Get ¶
Get returns the result of `get` call to R2Bucket.
- if the object for given key doesn't exist, returns nil.
- if a network error happens, returns error.
func (*R2Bucket) Head ¶
Head returns the result of `head` call to R2Bucket.
- Body field of *R2Object is always nil for Head call.
- if the object for given key doesn't exist, returns nil.
- if a network error happens, returns error.
func (*R2Bucket) List ¶
List returns the result of `list` call to R2Bucket.
- if a network error happens, returns error.
func (*R2Bucket) Put ¶
func (r *R2Bucket) Put(key string, value io.ReadCloser, opts *R2PutOptions) (*R2Object, error)
Put returns the result of `put` call to R2Bucket.
- This method copies all bytes into memory for implementation restriction.
- Body field of *R2Object is always nil for Put call.
- if a network error happens, returns error.
type R2HTTPMetadata ¶
type R2HTTPMetadata struct { ContentType string ContentLanguage string ContentDisposition string ContentEncoding string CacheControl string CacheExpiry time.Time }
R2HTTPMetadata represents metadata of R2Object.
type R2Object ¶
type R2Object struct { Key string Version string Size int ETag string HTTPETag string Uploaded time.Time HTTPMetadata R2HTTPMetadata CustomMetadata map[string]string // Body is a body of R2Object. // This value is nil for the result of the `Head` or `Put` method. Body io.Reader // contains filtered or unexported fields }
R2Object represents Cloudflare R2 object.
type R2Objects ¶
type R2Objects struct { Objects []*R2Object Truncated bool // Cursor indicates next cursor of R2Objects. // - This becomes empty string if cursor doesn't exist. Cursor string DelimitedPrefixes []string }
R2Objects represents Cloudflare R2 objects.
type R2PutOptions ¶
type R2PutOptions struct { HTTPMetadata R2HTTPMetadata CustomMetadata map[string]string MD5 string }
R2PutOptions represents Cloudflare R2 put options.