From 6da8494a568c3fc35a9e90bc8ea18d51c3edebe4 Mon Sep 17 00:00:00 2001 From: shynome Date: Fri, 28 Jul 2023 23:51:43 +0800 Subject: [PATCH] improve: support js,wasm --- transport.go | 2 +- transport_js.go | 17 +++++++++++++++++ transport_other.go | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 transport_js.go create mode 100644 transport_other.go diff --git a/transport.go b/transport.go index 63c273e2..191cd519 100644 --- a/transport.go +++ b/transport.go @@ -25,7 +25,7 @@ func createTransport(localAddr net.Addr) *http.Transport { } return &http.Transport{ Proxy: http.ProxyFromEnvironment, - DialContext: dialer.DialContext, + DialContext: transportDialContext(dialer), ForceAttemptHTTP2: true, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, diff --git a/transport_js.go b/transport_js.go new file mode 100644 index 00000000..6227aa9c --- /dev/null +++ b/transport_js.go @@ -0,0 +1,17 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build js && wasm +// +build js,wasm + +package resty + +import ( + "context" + "net" +) + +func transportDialContext(dialer *net.Dialer) func(context.Context, string, string) (net.Conn, error) { + return nil +} diff --git a/transport_other.go b/transport_other.go new file mode 100644 index 00000000..73553c36 --- /dev/null +++ b/transport_other.go @@ -0,0 +1,17 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !(js && wasm) +// +build !js !wasm + +package resty + +import ( + "context" + "net" +) + +func transportDialContext(dialer *net.Dialer) func(context.Context, string, string) (net.Conn, error) { + return dialer.DialContext +}