mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2025-03-11 09:39:10 +00:00
♻️
This commit is contained in:
parent
04f6573b78
commit
896b5a3cee
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Request builds and returns the equivalent http.Request
|
// Request builds and returns the equivalent http.Request
|
||||||
func Request(r js.Value) (*http.Request, error) {
|
func Request(r js.Value) *http.Request {
|
||||||
jsBody := js.Global().Get("Uint8Array").New(Promise{r.Call("arrayBuffer")}.Await())
|
jsBody := js.Global().Get("Uint8Array").New(Promise{r.Call("arrayBuffer")}.Await())
|
||||||
body := make([]byte, jsBody.Get("length").Int())
|
body := make([]byte, jsBody.Get("length").Int())
|
||||||
js.CopyBytesToGo(body, jsBody)
|
js.CopyBytesToGo(body, jsBody)
|
||||||
@ -29,5 +29,5 @@ func Request(r js.Value) (*http.Request, error) {
|
|||||||
req.Header.Set(v.Index(0).String(), v.Index(1).String())
|
req.Header.Set(v.Index(0).String(), v.Index(1).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return req, nil
|
return req
|
||||||
}
|
}
|
||||||
|
7
serve.go
7
serve.go
@ -38,14 +38,9 @@ func Serve(handler http.Handler) func() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var req, err = Request(args[0])
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var res = NewResponseRecorder()
|
var res = NewResponseRecorder()
|
||||||
|
|
||||||
h.ServeHTTP(res, req)
|
h.ServeHTTP(res, Request(args[0]))
|
||||||
|
|
||||||
resolve(res)
|
resolve(res)
|
||||||
}()
|
}()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user