Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add worker bindings #856

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ const (
WorkerSecretTextBindingType WorkerBindingType = "secret_text"
// WorkerPlainTextBindingType is the type for plain text bindings.
WorkerPlainTextBindingType WorkerBindingType = "plain_text"
// WorkerWorkerBindingType is the type for worker bindings.
WorkerWorkerBindingType WorkerBindingType = "service"
)

// WorkerBindingListItem a struct representing an individual binding in a list of bindings.
Expand Down Expand Up @@ -244,6 +246,33 @@ func (b WorkerPlainTextBinding) serialize(bindingName string) (workerBindingMeta
}, nil, nil
}

// WorkerWorkerBinding is a binding to another worker.
type WorkerWorkerBinding struct {
Worker string
Environment string
}

// Type returns the type of the binding.
func (b WorkerWorkerBinding) Type() WorkerBindingType {
return WorkerWorkerBindingType
}

func (b WorkerWorkerBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) {
if b.Worker == "" {
return nil, nil, errors.Errorf(`Worker for binding "%s" cannot be empty`, bindingName)
}
if b.Environment == "" {
return nil, nil, errors.Errorf(`Environment for binding "%s" cannot be empty`, bindingName)
}

return workerBindingMeta{
"name": bindingName,
"type": b.Type(),
"worker": b.Worker,
"environment": b.Environment,
}, nil, nil
}

// WorkerSecretTextBinding is a binding to secret text
//
// https://developers.cloudflare.com/workers/tooling/api/scripts/#add-a-secret-text-binding
Expand Down