⬆️ go 1.18 compatibility

This commit is contained in:
Nicolas Lepage 2022-07-28 00:08:56 +02:00
parent 624ed00220
commit 163b49702b
No known key found for this signature in database
GPG Key ID: B0879E35E66D8F6F
9 changed files with 12 additions and 12 deletions

View File

@ -96,7 +96,8 @@ Create a ServiceWorker file with the following code:
📄 `sw.js` 📄 `sw.js`
```js ```js
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.0.0/sw.js') importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.18.4/misc/wasm/wasm_exec.js')
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js')
registerWasmHTTPListener('path/to/server.wasm') registerWasmHTTPListener('path/to/server.wasm')
``` ```

View File

@ -1,4 +1,5 @@
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@078ff3547ebe2abfbee1fd5af9ca5ad64be480c0/sw.js') importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.18.4/misc/wasm/wasm_exec.js')
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js')
addEventListener('install', event => { addEventListener('install', event => {
event.waitUntil(skipWaiting()) event.waitUntil(skipWaiting())

Binary file not shown.

View File

@ -1,4 +1,5 @@
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.0.0/sw.js') importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.18.4/misc/wasm/wasm_exec.js')
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js')
addEventListener('install', (event) => { addEventListener('install', (event) => {
event.waitUntil(skipWaiting()) event.waitUntil(skipWaiting())

Binary file not shown.

View File

@ -1,4 +1,5 @@
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.0.0/sw.js') importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.18.4/misc/wasm/wasm_exec.js')
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js')
addEventListener('install', (event) => { addEventListener('install', (event) => {
event.waitUntil(skipWaiting()) event.waitUntil(skipWaiting())

View File

@ -6,7 +6,7 @@ import (
"syscall/js" "syscall/js"
) )
// ResponseRecorder extends httptest.ResponseRecorder and implements js.Wrapper // ResponseRecorder uses httptest.ResponseRecorder to build a JS Response
type ResponseRecorder struct { type ResponseRecorder struct {
*httptest.ResponseRecorder *httptest.ResponseRecorder
} }
@ -16,10 +16,8 @@ func NewResponseRecorder() ResponseRecorder {
return ResponseRecorder{httptest.NewRecorder()} return ResponseRecorder{httptest.NewRecorder()}
} }
var _ js.Wrapper = ResponseRecorder{} // JSResponse builds and returns the equivalent JS Response
func (rr ResponseRecorder) JSResponse() js.Value {
// JSValue builds and returns the equivalent JS Response (implementing js.Wrapper)
func (rr ResponseRecorder) JSValue() js.Value {
var res = rr.Result() var res = rr.Result()
var body js.Value = js.Undefined() var body js.Value = js.Undefined()

View File

@ -45,7 +45,7 @@ func Serve(handler http.Handler) func() {
h.ServeHTTP(res, Request(args[0])) h.ServeHTTP(res, Request(args[0]))
resolve(res) resolve(res.JSResponse())
}() }()
return resPromise return resPromise

2
sw.js
View File

@ -1,5 +1,3 @@
importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.15.7/misc/wasm/wasm_exec.js')
function registerWasmHTTPListener(wasm, { base, args = [] } = {}) { function registerWasmHTTPListener(wasm, { base, args = [] } = {}) {
let path = new URL(registration.scope).pathname let path = new URL(registration.scope).pathname
if (base && base !== '') path = `${trimEnd(path, '/')}/${trimStart(base, '/')}` if (base && base !== '') path = `${trimEnd(path, '/')}/${trimStart(base, '/')}`