Skip to content

Instantly share code, notes, and snippets.

@gen2brain
Created September 22, 2023 08:22
Show Gist options
  • Save gen2brain/9c9bfe31463ce65b5ea2a21fbff8d3e1 to your computer and use it in GitHub Desktop.
Save gen2brain/9c9bfe31463ce65b5ea2a21fbff8d3e1 to your computer and use it in GitHub Desktop.
diff --git a/client.go b/client.go
index bcf8d5b..0888b01 100644
--- a/client.go
+++ b/client.go
@@ -4,25 +4,34 @@ import (
"context"
"fmt"
"log"
+ "net"
"github.com/siashish/go-grpc/pb"
+
+ "github.com/stealthrocket/net/wasip1"
+
"google.golang.org/grpc"
+ "google.golang.org/grpc/credentials/insecure"
)
func main() {
- opts := grpc.WithInsecure()
- cc, err := grpc.Dial("localhost:8080", opts)
+ conn, err := grpc.Dial("127.0.0.1:8080",
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ grpc.WithContextDialer(func(ctx context.Context, address string) (net.Conn, error) {
+ return wasip1.DialContext(ctx, "tcp", address)
+ }),
+ )
if err != nil {
log.Fatal(err)
}
- defer cc.Close()
+ defer conn.Close()
- client := pb.NewGreetingServiceClient(cc)
+ client := pb.NewGreetingServiceClient(conn)
request := &pb.GreetingServiceRequest{Name: "Gophers"}
resp, err := client.Greeting(context.Background(), request)
if err != nil {
log.Fatal(err)
}
- fmt.Printf("Receive response => %s ", resp.Message)
+ fmt.Printf("Receive response => %s \n", resp.Message)
}
diff --git a/go.mod b/go.mod
index 20acf5f..04aa7d3 100644
--- a/go.mod
+++ b/go.mod
@@ -3,6 +3,7 @@ module github.com/siashish/go-grpc
go 1.20
require (
+ github.com/stealthrocket/net v0.2.1
google.golang.org/grpc v1.58.1
google.golang.org/protobuf v1.31.0
)
diff --git a/go.sum b/go.sum
index 11ed5d8..ad97258 100644
--- a/go.sum
+++ b/go.sum
@@ -3,6 +3,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
+github.com/stealthrocket/net v0.2.1 h1:PehPGAAjuV46zaeHGlNgakFV7QDGUAREMcEQsZQ8NLo=
+github.com/stealthrocket/net v0.2.1/go.mod h1:VvoFod9pYC9mo+bEg2NQB/D+KVOjxfhZjZ5zyvozq7M=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
diff --git a/server.go b/server.go
index babc871..3a61bdc 100644
--- a/server.go
+++ b/server.go
@@ -4,10 +4,11 @@ import (
"context"
"fmt"
"log"
- "net"
"github.com/siashish/go-grpc/pb"
+ "github.com/stealthrocket/net/wasip1"
+
"google.golang.org/grpc"
)
@@ -22,7 +23,7 @@ func (s *server) Greeting(ctx context.Context, req *pb.GreetingServiceRequest) (
}
func main() {
- listener, err := net.Listen("tcp", ":8080")
+ listener, err := wasip1.Listen("tcp", ":8080")
if err != nil {
panic(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment