mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
21 lines
477 B
Go
21 lines
477 B
Go
package fetch
|
|
|
|
import (
|
|
"net/http"
|
|
"syscall/js"
|
|
)
|
|
|
|
// transport is an implementation of http.RoundTripper
|
|
type transport struct {
|
|
// namespace - Objects that Fetch API belongs to. Default is Global
|
|
namespace js.Value
|
|
redirect RedirectMode
|
|
}
|
|
|
|
// RoundTrip replaces http.DefaultTransport.RoundTrip to use cloudflare fetch
|
|
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
return fetch(t.namespace, req, &RequestInit{
|
|
Redirect: t.redirect,
|
|
})
|
|
}
|