Skip to content

Commit

Permalink
Merge pull request #1293 from lafer-fz/optimize/pb-dynamic-import
Browse files Browse the repository at this point in the history
feat(generic): PB DynamicGo support importDirs
  • Loading branch information
felix021 committed Mar 12, 2024
2 parents 114e667 + 5fa16c1 commit 4fdd216
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions pkg/generic/jsonpb_test/idl/echo_import.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";
package test;

import "echo.proto";
// The greeting service definition.
option go_package = "./";


service EchoService {
rpc Echo (test.Request) returns (test.Response) {}
}
4 changes: 2 additions & 2 deletions pkg/generic/pbidl_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ func (p *PbContentProvider) Close() error {
}

// PbFileProviderWithDynamicGo
func NewPbFileProviderWithDynamicGo(main string, ctx context.Context, options dproto.Options) (PbDescriptorProviderDynamicGo, error) {
func NewPbFileProviderWithDynamicGo(main string, ctx context.Context, options dproto.Options, importDirs ...string) (PbDescriptorProviderDynamicGo, error) {
p := &PbFileProviderWithDynamicGo{
svcs: make(chan *dproto.ServiceDescriptor, 1),
}

svc, err := options.NewDescriptorFromPath(ctx, main)
svc, err := options.NewDescriptorFromPath(ctx, main, importDirs...)
if err != nil {
return nil, err
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/generic/pbidl_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,15 @@ func TestPbContentProviderDynamicGo(t *testing.T) {
svcDsc := <-p.Provide()
test.Assert(t, svcDsc != nil)
}

func TestPbFileProviderWithDynamicGo(t *testing.T) {
path := "./jsonpb_test/idl/echo_import.proto"

opts := dproto.Options{}
p, err := NewPbFileProviderWithDynamicGo(path, context.Background(), opts, "./jsonpb_test/idl")

test.Assert(t, err == nil)

svcDsc := <-p.Provide()
test.Assert(t, svcDsc != nil)
}

0 comments on commit 4fdd216

Please sign in to comment.