Skip to content

Instantly share code, notes, and snippets.

@marcellanz
Last active September 23, 2020 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcellanz/eae0c23837b709999748191ab7c3f287 to your computer and use it in GitHub Desktop.
Save marcellanz/eae0c23837b709999748191ab7c3f287 to your computer and use it in GitHub Desktop.
f.AsFileDescriptorProto
func protos() {
filenames, err := protoparse.ResolveFilenames([]string{"./proto/"}, "protocol/cloudstate/entity.proto")
if err != nil {
panic(err)
}
fmt.Printf("filenames: %+v\n", filenames)
p := protoparse.Parser{ImportPaths: []string{"./proto/"}}
files, err := p.ParseFiles(filenames...)
if err != nil {
panic(err)
}
fmt.Printf("files: %+v\n", files)
for _, f := range files {
file, err := protodesc.NewFile(f.AsFileDescriptorProto(), protoregistry.GlobalFiles)
if err != nil {
panic(err)
}
fmt.Printf("file: %+v\n", file)
service := file.Services().ByName("EntityDiscovery")
fmt.Printf("service: %+v\n", service)
discover := service.Methods().ByName("discover")
fmt.Printf("discover: %+v\n", discover)
input := dynamicpb.NewMessage(discover.Input())
fmt.Printf("input: %+v\n", discover.Input())
input.Set(discover.Input().Fields().ByJSONName("proxyName"), protoreflect.ValueOf("proxy-000"))
fmt.Printf("input: %+v\n", input)
conn, err := grpc.Dial("localhost:8080", grpc.WithInsecure())
if err != nil {
panic(err)
}
output := dynamicpb.NewMessage(discover.Output())
ctx, cancelFunc := context.WithTimeout(context.Background(), 15*time.Second)
defer cancelFunc()
err = conn.Invoke(ctx, "cloudstate.EntityDiscovery/discover", input, output, grpc.EmptyCallOption{})
if err != nil {
panic(err)
}
fmt.Printf("output: %+v\n", output)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment