Documentation
¶
Overview ¶
Package wasmhttp (github.com/nlepage/go-wasm-http-server) allows to create a WebAssembly Go HTTP Server embedded in a ServiceWorker.
It is a subset of the full solution, a full usage is available on the github repository: https://github.com/nlepage/go-wasm-http-server
Example (Json) ¶
Demonstrates a simple hello JSON service.
package main
import (
"encoding/json"
"fmt"
"net/http"
wasmhttp "github.com/nlepage/go-wasm-http-server"
)
func main() {
http.HandleFunc("/hello", func(res http.ResponseWriter, req *http.Request) {
params := make(map[string]string)
if err := json.NewDecoder(req.Body).Decode(¶ms); err != nil {
panic(err)
}
if err := json.NewEncoder(res).Encode(map[string]string{
"message": fmt.Sprintf("Hello %s!", params["name"]),
}); err != nil {
panic(err)
}
})
defer wasmhttp.Serve(nil)()
// Wait for webpage event or use empty select{}
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewPromise ¶
NewPromise creates a new JavaScript Promise
Types ¶
type ResponseRecorder ¶
type ResponseRecorder struct {
*httptest.ResponseRecorder
}
ResponseRecorder extends httptest.ResponseRecorder and implements js.Wrapper
func NewResponseRecorder ¶
func NewResponseRecorder() ResponseRecorder
NewResponseRecorder returns a new ResponseRecorder
func (ResponseRecorder) JSValue ¶
func (rr ResponseRecorder) JSValue() js.Value
JSValue builds and returns the equivalent JS Response (implementing js.Wrapper)
Click to show internal directories.
Click to hide internal directories.