gojs: refactors out gojs.Config type (#1240)

In order to support more configuration, we should stop using context as
it is getting gnarly.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Takeshi Yoneda
2023-03-14 21:27:47 -07:00
committed by GitHub
parent 00c53d19a2
commit f24a3f49a4
22 changed files with 228 additions and 142 deletions

View File

@@ -15,15 +15,6 @@ import (
// headersConstructor = Get("Headers").New() // http.Roundtrip && "fetch"
var headersConstructor = newJsVal(goos.RefHttpHeadersConstructor, "Headers")
type RoundTripperKey struct{}
func getRoundTripper(ctx context.Context) http.RoundTripper {
if rt, ok := ctx.Value(RoundTripperKey{}).(http.RoundTripper); ok {
return rt
}
return nil
}
// httpFetch implements jsFn for http.RoundTripper
//
// Reference in roundtrip_js.go init
@@ -33,10 +24,10 @@ func getRoundTripper(ctx context.Context) http.RoundTripper {
// In http.Transport RoundTrip, this returns a promise
//
// fetchPromise := js.Global().Call("fetch", req.URL.String(), opt)
type httpFetch struct{}
type httpFetch struct{ rt http.RoundTripper }
func (httpFetch) invoke(ctx context.Context, _ api.Module, args ...interface{}) (interface{}, error) {
rt := getRoundTripper(ctx)
func (h *httpFetch) invoke(ctx context.Context, _ api.Module, args ...interface{}) (interface{}, error) {
rt := h.rt
if rt == nil {
panic("unexpected to reach here without roundtripper as property is nil checked")
}