Skip to content

Commit

Permalink
Merge pull request #272 from bavix/upgrade-grpc
Browse files Browse the repository at this point in the history
upgrade grpc
  • Loading branch information
rez1dent3 authored May 15, 2024
2 parents c84b1ec + 1ecd6ef commit 53e5dd6
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 71 deletions.
11 changes: 6 additions & 5 deletions example/ms/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/google/uuid"
grpcinterceptors "github.com/gripmock/grpc-interceptors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

Expand All @@ -24,12 +25,12 @@ func env(key, fallback string) string {

//nolint:gomnd
func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

grpcPort := env("GRPC_PORT", "4770")

conn, err := grpc.DialContext(ctx, net.JoinHostPort("localhost", grpcPort), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
conn, err := grpc.NewClient(net.JoinHostPort("localhost", grpcPort),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithChainUnaryInterceptor(grpcinterceptors.UnaryTimeoutInterceptor(5*time.Second)),
grpc.WithChainStreamInterceptor(grpcinterceptors.StreamTimeoutInterceptor(5*time.Second)))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand All @@ -42,7 +43,7 @@ func main() {
u2bytes("99aebcf2-b56d-4923-9266-ab72bf5b9d0b"), // 1
u2bytes("5659bec5-dda5-4e87-bef4-e9e37c60eb1c"), // 2
u2bytes("77465064-a0ce-48a3-b7e4-d50f88e55093"), // 0
}})
}}, grpc.WaitForReady(true))
if err != nil {
log.Fatalf("error from grpc: %v", err)
}
Expand Down
11 changes: 6 additions & 5 deletions example/multi-files/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"time"

grpcinterceptors "github.com/gripmock/grpc-interceptors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

Expand All @@ -13,11 +14,11 @@ import (

//nolint:gomnd
func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

// Set up a connection to the server.
conn, err := grpc.DialContext(ctx, "localhost:4770", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
conn, err := grpc.NewClient("localhost:4770",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithChainUnaryInterceptor(grpcinterceptors.UnaryTimeoutInterceptor(5*time.Second)),
grpc.WithChainStreamInterceptor(grpcinterceptors.StreamTimeoutInterceptor(5*time.Second)))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand All @@ -26,7 +27,7 @@ func main() {
c := pb.NewGripmock1Client(conn)

// Contact the server and print out its response.
r, err := c.SayHello(context.Background(), &pb.Request1{Name: "tokopedia"})
r, err := c.SayHello(context.Background(), &pb.Request1{Name: "tokopedia"}, grpc.WaitForReady(true))
if err != nil {
log.Fatalf("error from grpc: %v", err)
}
Expand Down
13 changes: 7 additions & 6 deletions example/multi-package/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ import (
"os"
"time"

grpcinterceptors "github.com/gripmock/grpc-interceptors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

pb "github.com/bavix/gripmock/protogen/example/multi-package"
multi_package "github.com/bavix/gripmock/protogen/example/multi-package/bar"
multipackage "github.com/bavix/gripmock/protogen/example/multi-package/bar"
)

//nolint:gomnd
func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

// Set up a connection to the server.
conn, err := grpc.DialContext(ctx, "localhost:4770", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
conn, err := grpc.NewClient("localhost:4770",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithChainUnaryInterceptor(grpcinterceptors.UnaryTimeoutInterceptor(5*time.Second)),
grpc.WithChainStreamInterceptor(grpcinterceptors.StreamTimeoutInterceptor(5*time.Second)))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand All @@ -34,7 +35,7 @@ func main() {
name = os.Args[1]
}

r, err := c.Greet(context.Background(), &multi_package.Bar{Name: name})
r, err := c.Greet(context.Background(), &multipackage.Bar{Name: name}, grpc.WaitForReady(true))
if err != nil {
log.Fatalf("error from grpc: %v", err)
}
Expand Down
11 changes: 6 additions & 5 deletions example/one-of/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"time"

grpcinterceptors "github.com/gripmock/grpc-interceptors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

Expand All @@ -14,11 +15,11 @@ import (

//nolint:gomnd
func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

// Set up a connection to the server.
conn, err := grpc.DialContext(ctx, "localhost:4770", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
conn, err := grpc.NewClient("localhost:4770",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithChainUnaryInterceptor(grpcinterceptors.UnaryTimeoutInterceptor(5*time.Second)),
grpc.WithChainStreamInterceptor(grpcinterceptors.StreamTimeoutInterceptor(5*time.Second)))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand All @@ -31,7 +32,7 @@ func main() {
if len(os.Args) > 1 {
name = os.Args[1]
}
r, err := c.SayHello(context.Background(), &oneof.Request{Name: name})
r, err := c.SayHello(context.Background(), &oneof.Request{Name: name}, grpc.WaitForReady(true))
if err != nil {
log.Fatalf("error from grpc: %v", err)
}
Expand Down
13 changes: 7 additions & 6 deletions example/simple/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"time"

grpcinterceptors "github.com/gripmock/grpc-interceptors"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -18,11 +19,11 @@ import (

//nolint:gomnd
func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

// Set up a connection to the server.
conn, err := grpc.DialContext(ctx, "localhost:4770", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
conn, err := grpc.NewClient("localhost:4770",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithChainUnaryInterceptor(grpcinterceptors.UnaryTimeoutInterceptor(5*time.Second)),
grpc.WithChainStreamInterceptor(grpcinterceptors.StreamTimeoutInterceptor(5*time.Second)))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand All @@ -35,7 +36,7 @@ func main() {
if len(os.Args) > 1 {
name = os.Args[1]
}
r, err := c.SayHello(context.Background(), &pb.Request{Name: name})
r, err := c.SayHello(context.Background(), &pb.Request{Name: name}, grpc.WaitForReady(true))
if err != nil {
log.Fatalf("error from grpc: %v", err)
}
Expand Down Expand Up @@ -75,7 +76,7 @@ func main() {
log.Printf("Greeting: %s (return code %d)", r.GetMessage(), r.GetReturnCode())

md := metadata.New(map[string]string{"Authorization": "Basic dXNlcjp1c2Vy"})
ctx = metadata.NewOutgoingContext(context.Background(), md)
ctx := metadata.NewOutgoingContext(context.Background(), md)

var headers metadata.MD

Expand Down
16 changes: 8 additions & 8 deletions example/stream/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

grpcinterceptors "github.com/gripmock/grpc-interceptors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

Expand All @@ -17,11 +18,10 @@ import (
//nolint:gomnd
func main() {
// Set up a connection to the server.
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

// Set up a connection to the server.
conn, err := grpc.DialContext(ctx, "localhost:4770", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
conn, err := grpc.NewClient("localhost:4770",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithChainUnaryInterceptor(grpcinterceptors.UnaryTimeoutInterceptor(5*time.Second)),
grpc.WithChainStreamInterceptor(grpcinterceptors.StreamTimeoutInterceptor(5*time.Second)))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand Down Expand Up @@ -50,7 +50,7 @@ func serverStream(c pb.GripmockClient, wg *sync.WaitGroup) {
req := &pb.Request{
Name: "server-to-client-streaming",
}
stream, err := c.ServerStream(context.Background(), req)
stream, err := c.ServerStream(context.Background(), req, grpc.WaitForReady(true))
if err != nil {
log.Fatalf("server stream error: %v", err)
}
Expand All @@ -72,7 +72,7 @@ func serverStream(c pb.GripmockClient, wg *sync.WaitGroup) {
// client to server streaming.
func clientStream(c pb.GripmockClient, wg *sync.WaitGroup) {
defer wg.Done()
stream, err := c.ClientStream(context.Background())
stream, err := c.ClientStream(context.Background(), grpc.WaitForReady(true))
if err != nil {
log.Fatalf("c2s error: %v", err)
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func clientStream(c pb.GripmockClient, wg *sync.WaitGroup) {

// bidirectional stream.
func bidirectionalStream(c pb.GripmockClient, wg *sync.WaitGroup) {
stream, err := c.Bidirectional(context.Background())
stream, err := c.Bidirectional(context.Background(), grpc.WaitForReady(true))
if err != nil {
log.Fatalf("2ds error: %v", err)
}
Expand Down
11 changes: 6 additions & 5 deletions example/stub-subfolders/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"time"

grpcinterceptors "github.com/gripmock/grpc-interceptors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

Expand All @@ -13,11 +14,11 @@ import (

//nolint:gomnd
func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

// Set up a connection to the server.
conn, err := grpc.DialContext(ctx, "localhost:4770", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
conn, err := grpc.NewClient("localhost:4770",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithChainUnaryInterceptor(grpcinterceptors.UnaryTimeoutInterceptor(5*time.Second)),
grpc.WithChainStreamInterceptor(grpcinterceptors.StreamTimeoutInterceptor(5*time.Second)))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand All @@ -26,7 +27,7 @@ func main() {
c := pb.NewGripmockClient(conn)

// Contact the server and print out its response.
r, err := c.SayHello(context.Background(), &pb.Request{Name: "tokopedia"})
r, err := c.SayHello(context.Background(), &pb.Request{Name: "tokopedia"}, grpc.WaitForReady(true))
if err != nil {
log.Fatalf("error from grpc: %v", err)
}
Expand Down
11 changes: 6 additions & 5 deletions example/well_known_types/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"time"

grpcinterceptors "github.com/gripmock/grpc-interceptors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
empty "google.golang.org/protobuf/types/known/emptypb"
Expand All @@ -18,19 +19,19 @@ import (
//
//nolint:gomnd
func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

// Set up a connection to the server.
conn, err := grpc.DialContext(ctx, "localhost:4770", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
conn, err := grpc.NewClient("localhost:4770",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithChainUnaryInterceptor(grpcinterceptors.UnaryTimeoutInterceptor(5*time.Second)),
grpc.WithChainStreamInterceptor(grpcinterceptors.StreamTimeoutInterceptor(5*time.Second)))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()

c := pb.NewGripmockClient(conn)

r, err := c.ApiInfo(context.Background(), &empty.Empty{})
r, err := c.ApiInfo(context.Background(), &empty.Empty{}, grpc.WaitForReady(true))
if err != nil {
log.Fatalf("error from grpc: %v", err)
}
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/gorilla/handlers v1.5.2
github.com/gorilla/mux v1.8.1
github.com/gripmock/environment v1.0.1
github.com/gripmock/grpc-interceptors v1.0.1
github.com/gripmock/shutdown v1.0.0
github.com/gripmock/stuber v1.0.1
github.com/jhump/protoreflect v1.16.0
Expand All @@ -37,7 +38,7 @@ require (
github.com/caarlos0/env/v10 v10.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand All @@ -55,8 +56,8 @@ require (
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240506185236-b8a5c65736ae // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240506185236-b8a5c65736ae // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
Expand Down Expand Up @@ -56,6 +56,8 @@ github.com/gripmock/deeply v1.0.9 h1:6qijvx2LJchoNPQMT43iLi9SZKQ84oXR15x8x2FnOUY
github.com/gripmock/deeply v1.0.9/go.mod h1:xKJ9we/cU0CnCoYa+En2MirViTzvgsNp5B0hya1DhKk=
github.com/gripmock/environment v1.0.1 h1:4uZMrKZk+lOr4iSY1esJRd4j1VWdnYB42YoBQCwoKPY=
github.com/gripmock/environment v1.0.1/go.mod h1:nzBAHAw6/OYsng65X5q6HVmTmKtlvTHVdI/0OK1GGgQ=
github.com/gripmock/grpc-interceptors v1.0.1 h1:lNf+pahSOBHKH5qUlCAd0yVoG8g4YQVuWnf17JkKZjI=
github.com/gripmock/grpc-interceptors v1.0.1/go.mod h1:JZAMskq4QMGakdw8L9a5vBOEMrlJOyl/c64DN8s9xTA=
github.com/gripmock/shutdown v1.0.0 h1:ESDCCBeNHazgAstCpIskaORNWH3b+P03a2gznW+8IFY=
github.com/gripmock/shutdown v1.0.0/go.mod h1:YwyI7uYgIPPdR9k8QNHwzDI2mQNpUSu+WT9mvqVoty4=
github.com/gripmock/stuber v1.0.1 h1:Wml8OxiISjpxuBCztzLc60jbeU+kpgh7HLbbjrkCwGo=
Expand Down Expand Up @@ -181,10 +183,10 @@ golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
google.golang.org/genproto/googleapis/api v0.0.0-20240506185236-b8a5c65736ae h1:AH34z6WAGVNkllnKs5raNq3yRq93VnjBG6rpfub/jYk=
google.golang.org/genproto/googleapis/api v0.0.0-20240506185236-b8a5c65736ae/go.mod h1:FfiGhwUm6CJviekPrc0oJ+7h29e+DmWU6UtjX0ZvI7Y=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240506185236-b8a5c65736ae h1:c55+MER4zkBS14uJhSZMGGmya0yJx5iHV4x/fpOSNRk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240506185236-b8a5c65736ae/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM=
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 h1:W5Xj/70xIA4x60O/IFyXivR5MGqblAb8R3w26pnD6No=
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8/go.mod h1:vPrPUTsDCYxXWjP7clS81mZ6/803D8K4iM9Ma27VKas=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 h1:mxSlqyb8ZAHsYDCfiXN1EDdNTdvjUJSLY+OnAUtYNYA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"syscall"
"time"

_ "github.com/gripmock/grpc-interceptors"
"github.com/rs/zerolog"
_ "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
_ "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
Expand Down
2 changes: 1 addition & 1 deletion protogen/example/ms/ms.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protogen/example/multi-files/file1.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protogen/example/multi-files/file2.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protogen/example/multi-package/bar/bar.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 53e5dd6

Please sign in to comment.