Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(*): update example #5

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions example/discovery/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,26 @@ func main() {
log.Fatal(err)
}
client := pb.NewDiscoveryServiceClient(conn)
req := &pb.ListProductsRequest{

// for normal response that return all fields
normalRequest := &pb.ListProductsRequest{
Id: "1"}

resp, err := client.ListProducts(context.Background(), normalRequest)
if err != nil {
log.Fatal(err)
}
fmt.Println("resp for normal request", resp)

// request that use field mask
fieldMaskReq := &pb.ListProductsRequest{
Id: "1", FieldMask: &fieldmaskpb.FieldMask{
Paths: []string{"result.products.id", "result.products.price"},
}}

resp, err := client.ListProducts(context.Background(), req)
resp, err = client.ListProducts(context.Background(), fieldMaskReq)
if err != nil {
log.Fatal(err)
}
fmt.Println("resp", resp)
fmt.Println("resp with field mask", resp)
}
3 changes: 2 additions & 1 deletion interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"context"
"testing"

discoveryv1 "github.com/linhbkhn95/go-grpc-middleware-field-mask/pb/go/discovery/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/fieldmaskpb"

discoveryv1 "github.com/linhbkhn95/go-grpc-middleware-field-mask/pb/go/discovery/v1"
)

func TestFieldMaskSuite(t *testing.T) {
Expand Down
Loading