This commit is contained in:
Nicolas Lepage 2019-11-27 07:22:07 +01:00
parent 40c75880da
commit 9c65a54a24
No known key found for this signature in database
GPG Key ID: B0879E35E66D8F6F
8 changed files with 25 additions and 6 deletions

View File

@ -26,6 +26,14 @@ yarn add go-wasm-http-server
TODO
## Why?
TODO
## How?
TODO
## Author
👤 **Nicolas Lepage**

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module github.com/nlepage/go-wasm-http-server
go 1.12

View File

@ -0,0 +1,3 @@
// Package whutil stands for WASM HTTP utilities.
// It contains internal utilities for github.com/nlepage/go-wasm-http-server.
package whutil

View File

@ -1,4 +1,4 @@
package wasmhttp
package whutil
import (
"syscall/js"

View File

@ -1,4 +1,4 @@
package wasmhttp
package whutil
import (
"bytes"

View File

@ -1,4 +1,4 @@
package wasmhttp
package whutil
import (
"bytes"

3
package.go Normal file
View File

@ -0,0 +1,3 @@
// Package wasmhttp (github.com/nlepae/go-wasm-http-server) allows to create a WebAssembly Go HTTP Server embedded in a ServiceWorker.
// This package is a subset of the full solution, a full usage is available on the <a href="https://github.com/nlepage/go-wasm-http-server">github repository</a>.
package wasmhttp

View File

@ -4,6 +4,8 @@ import (
"net/http"
"os"
"syscall/js"
"github.com/nlepage/go-wasm-http-server/internal/whutil"
)
// Serve serves HTTP requests using handler or http.DefaultServeMux if handler is nil
@ -14,10 +16,10 @@ func Serve(handler http.Handler) func() {
}
cb := js.FuncOf(func(_ js.Value, args []js.Value) interface{} {
jsReq := Request(args[0])
jsReq := whutil.Request(args[0])
var resolveRes func(interface{})
var res = NewPromise(func(resolve, _ func(interface{})) {
var res = whutil.NewPromise(func(resolve, _ func(interface{})) {
resolveRes = resolve
})
@ -28,7 +30,7 @@ func Serve(handler http.Handler) func() {
panic(err)
}
res := NewResponseWriter()
res := whutil.NewResponseWriter()
handler.ServeHTTP(res, req)