ampedxx-yrpc 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="CompassSettings">
4
+ <option name="compassExecutableFilePath" value="$USER_HOME$/.rvm/gems/ruby-2.3.1/gems/compass-1.0.3/bin/compass" />
5
+ </component>
6
+ <component name="ModuleRunConfigurationManager">
7
+ <shared />
8
+ </component>
9
+ <component name="NewModuleRootManager">
10
+ <content url="file://$MODULE_DIR$" />
11
+ <orderEntry type="inheritedJdk" />
12
+ <orderEntry type="sourceFolder" forTests="false" />
13
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.16.2, RVM: ruby-2.3.1) [gem]" level="application" />
14
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.3, RVM: ruby-2.3.1) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="kramdown (v1.17.0, RVM: ruby-2.3.1) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, RVM: ruby-2.3.1) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.7.0, RVM: ruby-2.3.1) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.7.1, RVM: ruby-2.3.1) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.7.0, RVM: ruby-2.3.1) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.7.0, RVM: ruby-2.3.1) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.7.1, RVM: ruby-2.3.1) [gem]" level="application" />
22
+ </component>
23
+ </module>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at 351711778@qq.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in yrpc.gemspec
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ gem 'kramdown'
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.3)
5
+ kramdown (1.17.0)
6
+ rake (10.5.0)
7
+ rspec (3.7.0)
8
+ rspec-core (~> 3.7.0)
9
+ rspec-expectations (~> 3.7.0)
10
+ rspec-mocks (~> 3.7.0)
11
+ rspec-core (3.7.1)
12
+ rspec-support (~> 3.7.0)
13
+ rspec-expectations (3.7.0)
14
+ diff-lcs (>= 1.2.0, < 2.0)
15
+ rspec-support (~> 3.7.0)
16
+ rspec-mocks (3.7.0)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.7.0)
19
+ rspec-support (3.7.1)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ kramdown
26
+ rake
27
+ rspec
28
+
29
+ BUNDLED WITH
30
+ 1.16.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 icepoint0
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,207 @@
1
+ # Yrpc
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yrpc`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'yrpc'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install yrpc
23
+
24
+ ## Usage
25
+
26
+
27
+ 云深rpc 针对grpc的一次封装开发,类rails 开发模式
28
+
29
+ 项目结构:server 端
30
+
31
+ ```java
32
+ app
33
+ --controllers
34
+ --controller..
35
+
36
+ ```
37
+
38
+ 首先使用 yrpc-cli 生成我们的proto_buff 文件
39
+
40
+ ```shell
41
+ $ yrpc-cli ./protos lib
42
+ ```
43
+
44
+ 例子在 yrpc-test 项目中
45
+
46
+ 生成 app/controllers 目录
47
+
48
+ ```shell
49
+ $ yrpc-cli -g
50
+ ```
51
+
52
+ 添加第一个ruby controller
53
+
54
+ ```ruby
55
+
56
+ class DemoServer < Yrpc::Controllers::Base
57
+ bind ::Demo::Demoer::Service
58
+ before_action [:test_invoke, :error]
59
+
60
+ def say_hello
61
+ Demo::HelloReply.new(message: "Hello #{request.message.name}")
62
+ end
63
+
64
+ def test_invoke
65
+ request.message.name = "asd"
66
+ end
67
+
68
+ def error
69
+ request.raise_need_login("mesasge")
70
+ end
71
+
72
+ end
73
+
74
+ ```
75
+
76
+ 首先使用bind 将我们的生成的grpc service 绑定,
77
+
78
+ ```
79
+ bind ::Demo::Demoer::Service
80
+ ```
81
+
82
+ SayHello.underscore 为我们需要覆写的方法。
83
+
84
+ ```
85
+ say_hello #方法override
86
+
87
+ ```
88
+
89
+ controller 带过滤器
90
+
91
+ ```
92
+ before_action
93
+
94
+ after_action
95
+ ```
96
+
97
+ controller 已经编写好 接下来创建第一个yrpc server
98
+
99
+ yrpc-server.rb
100
+
101
+ ```ruby
102
+ require 'yrpc'
103
+ require './lib/helloworld_services_pb'
104
+
105
+ Yrpc.configure do |y|
106
+ y.server_options = {}
107
+ y.controllers_path = 'app/controllers'
108
+ end
109
+ #
110
+ Yrpc::Executor.new.run
111
+
112
+ ```
113
+ 默认开启的端口为 9001 可以自己进行配置
114
+
115
+ -> y.server_ binding_ url:
116
+
117
+ 配置了controller_path 就可以自动load 所有controller了
118
+
119
+
120
+ 现在编写client 试试我们的 server 是否生效
121
+
122
+
123
+ yrpc-client.rb
124
+
125
+ ```ruby
126
+ require 'yrpc'
127
+ require './lib/helloworld_services_pb'
128
+
129
+ def main
130
+ begin
131
+ client = ::Yrpc::Client.new(service: Demo::Demoer, options: {hostname: "localhost:9001"})
132
+ response = client.invoke(:SayHello, name: "sad")
133
+ message = response.message.status
134
+ p "Greeting: #{message.code}"
135
+ rescue => e
136
+ p e
137
+ end
138
+ end
139
+
140
+ main
141
+ ```
142
+
143
+ 注意! 这里同样需要引用到我们的service类 客户端和服务端需要共同引入
144
+
145
+
146
+ ##规范
147
+
148
+ 遵循大部分云深response 规范的protocal 文件格式应该为
149
+
150
+
151
+ ```java
152
+
153
+ service demoer {
154
+ // Sends a greeting
155
+ rpc SayHello (HelloRequest) returns (HelloReply) {
156
+ }
157
+ }
158
+
159
+ // The request message containing the user's name.
160
+ message HelloRequest {
161
+ string name = 1;
162
+ }
163
+
164
+ // The response message containing the greetings
165
+ message HelloReply {
166
+ Status status = 1;
167
+ }
168
+
169
+ message Status {
170
+ string message = 1;
171
+ string code = 2;
172
+ }
173
+
174
+
175
+ ```
176
+
177
+ Hello Reply 应当带一个nest type
178
+
179
+ 即 返回的时候 带 data.status.code ,data.status.message
180
+
181
+ 即通过code 判断接口是否成功
182
+
183
+
184
+ 相关资料
185
+
186
+ [GRPC](https://grpc.io/docs/quickstart/ruby.html)
187
+
188
+ [Protocal Language](https://developers.google.com/protocol-buffers/docs/proto3)
189
+
190
+
191
+ ## Development
192
+
193
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
194
+
195
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
196
+
197
+ ## Contributing
198
+
199
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yrpc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
200
+
201
+ ## License
202
+
203
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
204
+
205
+ ## Code of Conduct
206
+
207
+ Everyone interacting in the Yrpc project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/yrpc/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yrpc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ require 'yrpc'
2
+ help = <<HELP
3
+ yrpc-cli: Atyun grpc pb generator
4
+ proto入口文件 和ruby输出文件 路径
5
+ $ yrpc-cli input_path outputpath
6
+ HELP
7
+ input = ARGV[0]
8
+ output = ARGV[1]
9
+ if %w{-h --help}.any? { |c| ARGV.include? c }
10
+ puts help
11
+ elsif %w{-g --generate}.any? { |c| ARGV.include? c }
12
+ #gernate path
13
+ system("mkdir app/controllers")
14
+ else
15
+ system("grpc_tools_ruby_protoc -I #{input} --ruby_out=#{output} --grpc_out=#{output} #{input}/*")
16
+ end
17
+
18
+ #
19
+
@@ -0,0 +1,29 @@
1
+ require 'grpc'
2
+
3
+ require 'active_support/core_ext/module/delegation'
4
+ require 'active_support/concern'
5
+ require 'active_support/inflector'
6
+ require 'active_support/callbacks'
7
+ require 'active_support'
8
+ require 'active_support/dependencies'
9
+
10
+ require_relative "yrpc/helpers/autoload"
11
+ require "yrpc/version"
12
+ require_relative "yrpc/client"
13
+ require_relative "yrpc/configuration"
14
+ require_relative "yrpc/executor/executor"
15
+ require_relative "yrpc/server"
16
+ require_relative "yrpc/controllers/base"
17
+ require_relative "yrpc/controllers/service_binder"
18
+ require_relative "yrpc/interceptors/register"
19
+ require_relative "yrpc/controllers/request"
20
+ require_relative "yrpc/controllers/response"
21
+ require_relative "yrpc/error/response_error"
22
+ require_relative "yrpc/outbound/request_context"
23
+ require_relative 'yrpc/interceptors/client_interceptor'
24
+
25
+
26
+
27
+ module Yrpc
28
+ extend Configuration
29
+ end