mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2026-01-12 01:59:14 +00:00
🚧
This commit is contained in:
@@ -26,6 +26,14 @@ yarn add go-wasm-http-server
|
||||
|
||||
TODO
|
||||
|
||||
## Why?
|
||||
|
||||
TODO
|
||||
|
||||
## How?
|
||||
|
||||
TODO
|
||||
|
||||
## Author
|
||||
|
||||
👤 **Nicolas Lepage**
|
||||
|
||||
3
go.mod
Normal file
3
go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module github.com/nlepage/go-wasm-http-server
|
||||
|
||||
go 1.12
|
||||
3
internal/whutil/package.go
Normal file
3
internal/whutil/package.go
Normal 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
|
||||
@@ -1,4 +1,4 @@
|
||||
package wasmhttp
|
||||
package whutil
|
||||
|
||||
import (
|
||||
"syscall/js"
|
||||
@@ -1,4 +1,4 @@
|
||||
package wasmhttp
|
||||
package whutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -1,4 +1,4 @@
|
||||
package wasmhttp
|
||||
package whutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
3
package.go
Normal file
3
package.go
Normal 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
|
||||
8
serve.go
8
serve.go
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user