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

Use custom for of grpc-go and unify client and server

This commit is contained in:
Johan Brandhorst
2018-06-25 15:48:55 +01:00
parent 3d89b1de82
commit c7ec9fde8c
71 changed files with 2734 additions and 4250 deletions

File diff suppressed because one or more lines are too long

View File

@@ -4,25 +4,36 @@ import (
"context"
"fmt"
"io"
"os"
_ "google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/status"
grpc "github.com/johanbrandhorst/grpc-wasm"
server "github.com/johanbrandhorst/wasm-experiments/grpc/proto/client"
web "github.com/johanbrandhorst/wasm-experiments/grpc/proto"
)
// Build with Go WASM fork
//go:generate rm -f ./html/test.wasm
//go:generate bash -c "GOOS=js GOARCH=wasm GOROOT=$GOPATH/src/github.com/neelance/go/ $GOPATH/src/github.com/neelance/go/bin/go build -o ./html/test.wasm frontend.go"
//go:generate bash -c "GOOS=js GOARCH=wasm GOROOT=$GOPATH/src/github.com/johanbrandhorst/go/ $GOPATH/src/github.com/johanbrandhorst/go/bin/go build -o ./html/test.wasm frontend.go"
// Integrate generated JS into a Go file for static loading.
//go:generate bash -c "go run assets_generate.go"
func init() {
// Should only be done from init functions
grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stdout, os.Stdout, os.Stdout))
}
func main() {
cc, _ := grpc.Dial("")
client := server.NewBackendClient(cc)
resp, err := client.GetUser(context.Background(), &server.GetUserRequest{
cc, err := grpc.Dial("")
if err != nil {
fmt.Println(err)
return
}
client := web.NewBackendClient(cc)
resp, err := client.GetUser(context.Background(), &web.GetUserRequest{
UserId: "1234",
})
if err != nil {
@@ -31,7 +42,7 @@ func main() {
} else {
fmt.Println(resp.GetId())
}
resp, err = client.GetUser(context.Background(), &server.GetUserRequest{
resp, err = client.GetUser(context.Background(), &web.GetUserRequest{
UserId: "123",
})
if err != nil {
@@ -41,7 +52,7 @@ func main() {
fmt.Println(resp.GetId())
}
srv, err := client.GetUsers(context.Background(), &server.GetUsersRequest{
srv, err := client.GetUsers(context.Background(), &web.GetUsersRequest{
NumUsers: 3,
})
if err != nil {

View File

@@ -41,6 +41,11 @@
}
return buf.length;
},
openSync(path, flags, mode) {
const err = new Error("not implemented");
err.code = "ENOSYS";
throw err;
},
};
}
@@ -369,6 +374,7 @@
return go.run(result.instance);
}).catch((err) => {
console.error(err);
go.exited = true;
process.exit(1);
});
}