1
0
mirror of https://github.com/taigrr/wasm-experiments synced 2025-01-18 04:03:21 -08:00

Remove gRPC example, add some simpler examples

This commit is contained in:
Johan Brandhorst
2018-08-11 20:55:13 +01:00
parent 1bb4e7fb1e
commit 0d5389317f
662 changed files with 942 additions and 368637 deletions

View File

@@ -1,7 +0,0 @@
build: clean compile
clean:
rm -f ../html/test.wasm
compile:
GOOS=js GOARCH=wasm GOROOT=$(GOPATH)/src/github.com/johanbrandhorst/go/ $(GOPATH)/src/github.com/johanbrandhorst/go/bin/go build -o ../html/test.wasm main.go

View File

@@ -3,42 +3,37 @@
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
"github.com/johanbrandhorst/fetch"
"github.com/dennwc/dom"
"github.com/johanbrandhorst/wasm-experiments/div"
)
func main() {
c := http.Client{
Transport: &fetch.Transport{},
}
t := dom.GetDocument().GetElementById("target")
logger := log.New((*div.Writer)(t), "", log.LstdFlags)
c := http.Client{}
req, err := http.NewRequest(
"POST",
"https://httpbin.org/anything",
strings.NewReader(`{"test":"test"}`),
)
if err != nil {
fmt.Println(err)
return
logger.Fatal(err)
}
/*
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*200)
defer cancel()
req = req.WithContext(ctx)
*/
resp, err := c.Do(req)
if err != nil {
fmt.Println(err)
return
logger.Fatal(err)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
return
logger.Fatal(err)
}
fmt.Println(string(b))
logger.Print(string(b))
}