Skip to content

Commit

Permalink
changes from review
Browse files Browse the repository at this point in the history
- Fix lints
- Add changelog
- Document unsafe binding with example
  • Loading branch information
aaronlisman committed Jul 12, 2023
1 parent 0de7841 commit 60451aa
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .changelog/1330.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```release-note:enhancement
workers: Add support for uploading scripts to a Workers for Platforms namespace.
```

```release-note:enhancement
workers: Add support for declaring arbitrary bindings with UnsafeBinding.
```

```release-note:enhancement
workers: Add support for uploading workers with Workers for Platforms namespace bindings.
```

```release-note:enhancement
workers: Add `pipeline_hash` field to Workers script response struct.
```
2 changes: 1 addition & 1 deletion workers_bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (b DispatchNamespaceBinding) serialize(bindingName string) (workerBindingMe
return meta, nil, nil
}

// UnsafeBinding is for experimental or deprecated bindings, and allows specifying any binding type or property
// UnsafeBinding is for experimental or deprecated bindings, and allows specifying any binding type or property.
type UnsafeBinding map[string]interface{}

// Type returns the type of the binding.
Expand Down
43 changes: 43 additions & 0 deletions workers_bindings_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cloudflare

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -95,3 +97,44 @@ func TestListWorkerBindings(t *testing.T) {
})
assert.Equal(t, WorkerAnalyticsEngineBindingType, res.BindingList[7].Binding.Type())
}

func ExampleUnsafeBinding() {
pretty := func(meta workerBindingMeta) string {
buf := bytes.NewBufferString("")
encoder := json.NewEncoder(buf)
encoder.SetIndent("", " ")
encoder.Encode(meta)
return buf.String()
}

binding_a := WorkerServiceBinding{
Service: "foo",
}
meta_a, _, _ := binding_a.serialize("my_binding")
meta_a_json := pretty(meta_a)
fmt.Println(meta_a_json)

binding_b := UnsafeBinding{
"type": "service",
"service": "foo",
}
meta_b, _, _ := binding_b.serialize("my_binding")
meta_b_json := pretty(meta_b)
fmt.Println(meta_b_json)

fmt.Println(meta_a_json == meta_b_json)
// Output:
// {
// "name": "my_binding",
// "service": "foo",
// "type": "service"
// }
//
// {
// "name": "my_binding",
// "service": "foo",
// "type": "service"
// }
//
// true
}

0 comments on commit 60451aa

Please sign in to comment.