mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
R: add WithBinding in fetch
This commit is contained in:
parent
8b39614bbd
commit
ef831af9d7
@ -12,9 +12,30 @@ type Client struct {
|
||||
namespace js.Value
|
||||
}
|
||||
|
||||
// NewClient returns new Client
|
||||
func NewClient() *Client {
|
||||
return &Client{
|
||||
namespace: jsutil.Global,
|
||||
// applyOptions applies client options.
|
||||
func (c *Client) applyOptions(opts []ClientOption) {
|
||||
for _, opt := range opts {
|
||||
opt(c)
|
||||
}
|
||||
}
|
||||
|
||||
// ClientOption is a type that represents an optional function.
|
||||
type ClientOption func(*Client)
|
||||
|
||||
// WithBinding changes the objects that Fetch API belongs to.
|
||||
// This is useful for service bindings, mTLS, etc.
|
||||
func WithBinding(bind js.Value) ClientOption {
|
||||
return func(c *Client) {
|
||||
c.namespace = bind
|
||||
}
|
||||
}
|
||||
|
||||
// NewClient returns new Client
|
||||
func NewClient(opts ...ClientOption) *Client {
|
||||
c := &Client{
|
||||
namespace: jsutil.Global,
|
||||
}
|
||||
c.applyOptions(opts)
|
||||
|
||||
return c
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user