зеркало из https://github.com/arthurnn/twirp-ruby.git
Merge pull request #15 from twitchtv/nested_package_example
Add nested package to the example.
This commit is contained in:
Коммит
81933efa5d
|
@ -1,5 +1,7 @@
|
|||
# Twirp HelloWorld Example
|
||||
|
||||
### Run the example
|
||||
|
||||
To run the example, first make sure you are in the /example folder:
|
||||
```sh
|
||||
cd example
|
||||
|
@ -29,18 +31,18 @@ To send requests from Ruby code, runt he hello_world client example:
|
|||
bundle exec ruby hello_world_client.rb
|
||||
```
|
||||
|
||||
### Run code generator
|
||||
### Run code generation
|
||||
|
||||
Try to add a new field in `./hello_world/service.proto`, then run the generator code and see if the new field was properly added in the generated files.
|
||||
|
||||
Make sure you have the [protobuf compiler](https://github.com/golang/protobuf) (version 3+).
|
||||
|
||||
Install the twirp plugin with go:
|
||||
```sh
|
||||
go get -u github.com/cyrusaf/ruby-twirp/protoc-gen-twirp_ruby
|
||||
go get -u github.com/twitchtv/twirp-ruby/protoc-gen-twirp_ruby
|
||||
```
|
||||
|
||||
From the `/example` folder, run the generator command:
|
||||
```sh
|
||||
protoc --proto_path=. ./hello_world/service.proto --ruby_out=. --twirp_ruby_out=.
|
||||
```
|
||||
|
||||
Try to add a new field in `./hello_world/service.proto`, then run the generator code and see if the new field was properly added in the generated files.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
syntax = "proto3";
|
||||
package example;
|
||||
package example.hello_world;
|
||||
|
||||
service HelloWorld {
|
||||
rpc Hello(HelloRequest) returns (HelloResponse);
|
||||
|
|
|
@ -4,15 +4,17 @@
|
|||
require 'google/protobuf'
|
||||
|
||||
Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
add_message "example.HelloRequest" do
|
||||
add_message "example.hello_world.HelloRequest" do
|
||||
optional :name, :string, 1
|
||||
end
|
||||
add_message "example.HelloResponse" do
|
||||
add_message "example.hello_world.HelloResponse" do
|
||||
optional :message, :string, 1
|
||||
end
|
||||
end
|
||||
|
||||
module Example
|
||||
HelloRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("example.HelloRequest").msgclass
|
||||
HelloResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("example.HelloResponse").msgclass
|
||||
module HelloWorld
|
||||
HelloRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("example.hello_world.HelloRequest").msgclass
|
||||
HelloResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("example.hello_world.HelloResponse").msgclass
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# Code generated by protoc-gen-twirp_ruby, DO NOT EDIT.
|
||||
require 'twirp'
|
||||
|
||||
module Example
|
||||
module Example.helloWorld
|
||||
class HelloWorldService < Twirp::Service
|
||||
package "example"
|
||||
package "example.hello_world"
|
||||
service "HelloWorld"
|
||||
rpc :Hello, HelloRequest, HelloResponse, :ruby_method => :hello
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|||
spec.email = ["forbescyrus@gmail.com", "tothemario@gmail.com"]
|
||||
spec.summary = %q{Twirp services in Ruby.}
|
||||
spec.description = %q{Twirp is a simple RPC framework with protobuf service definitions. The Twirp gem provides native support for Ruby.}
|
||||
spec.homepage = "https://github.com/cyrusaf/ruby-twirp"
|
||||
spec.homepage = "https://github.com/twitchtv/twirp-ruby"
|
||||
spec.license = "MIT"
|
||||
|
||||
spec.files = Dir['lib/**/*'] + %w(Gemfile LICENSE README.md twirp.gemspec)
|
||||
|
|
Загрузка…
Ссылка в новой задаче