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

Fix check reply argument type #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion gee-rpc/day3-service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *service) registerMethods() {
continue
}
argType, replyType := mType.In(1), mType.In(2)
if !isExportedOrBuiltinType(argType) || !isExportedOrBuiltinType(replyType) {
if !isExportedOrBuiltinType(argType) || !isExportedOrBuiltinType(replyType) || !isPtrType(replyType) {
continue
}
s.method[method.Name] = &methodType{
Expand All @@ -95,5 +95,10 @@ func (s *service) call(m *methodType, argv, replyv reflect.Value) error {
}

func isExportedOrBuiltinType(t reflect.Type) bool {

return ast.IsExported(t.Name()) || t.PkgPath() == ""
}

func isPtrType(t reflect.Type) bool {
return t.Kind() == reflect.Ptr
}
7 changes: 6 additions & 1 deletion gee-rpc/day4-timeout/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *service) registerMethods() {
continue
}
argType, replyType := mType.In(1), mType.In(2)
if !isExportedOrBuiltinType(argType) || !isExportedOrBuiltinType(replyType) {
if !isExportedOrBuiltinType(argType) || !isExportedOrBuiltinType(replyType) || !isPtrType(replyType) {
continue
}
s.method[method.Name] = &methodType{
Expand All @@ -95,5 +95,10 @@ func (s *service) call(m *methodType, argv, replyv reflect.Value) error {
}

func isExportedOrBuiltinType(t reflect.Type) bool {

return ast.IsExported(t.Name()) || t.PkgPath() == ""
}

func isPtrType(t reflect.Type) bool {
return t.Kind() == reflect.Ptr
}
7 changes: 6 additions & 1 deletion gee-rpc/day5-http-debug/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *service) registerMethods() {
continue
}
argType, replyType := mType.In(1), mType.In(2)
if !isExportedOrBuiltinType(argType) || !isExportedOrBuiltinType(replyType) {
if !isExportedOrBuiltinType(argType) || !isExportedOrBuiltinType(replyType) || !isPtrType(replyType) {
continue
}
s.method[method.Name] = &methodType{
Expand All @@ -95,5 +95,10 @@ func (s *service) call(m *methodType, argv, replyv reflect.Value) error {
}

func isExportedOrBuiltinType(t reflect.Type) bool {

return ast.IsExported(t.Name()) || t.PkgPath() == ""
}

func isPtrType(t reflect.Type) bool {
return t.Kind() == reflect.Ptr
}
7 changes: 6 additions & 1 deletion gee-rpc/day6-load-balance/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *service) registerMethods() {
continue
}
argType, replyType := mType.In(1), mType.In(2)
if !isExportedOrBuiltinType(argType) || !isExportedOrBuiltinType(replyType) {
if !isExportedOrBuiltinType(argType) || !isExportedOrBuiltinType(replyType) || !isPtrType(replyType) {
continue
}
s.method[method.Name] = &methodType{
Expand All @@ -95,5 +95,10 @@ func (s *service) call(m *methodType, argv, replyv reflect.Value) error {
}

func isExportedOrBuiltinType(t reflect.Type) bool {

return ast.IsExported(t.Name()) || t.PkgPath() == ""
}

func isPtrType(t reflect.Type) bool {
return t.Kind() == reflect.Ptr
}
7 changes: 6 additions & 1 deletion gee-rpc/day7-registry/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *service) registerMethods() {
continue
}
argType, replyType := mType.In(1), mType.In(2)
if !isExportedOrBuiltinType(argType) || !isExportedOrBuiltinType(replyType) {
if !isExportedOrBuiltinType(argType) || !isExportedOrBuiltinType(replyType) || !isPtrType(replyType) {
continue
}
s.method[method.Name] = &methodType{
Expand All @@ -95,5 +95,10 @@ func (s *service) call(m *methodType, argv, replyv reflect.Value) error {
}

func isExportedOrBuiltinType(t reflect.Type) bool {

return ast.IsExported(t.Name()) || t.PkgPath() == ""
}

func isPtrType(t reflect.Type) bool {
return t.Kind() == reflect.Ptr
}
2 changes: 1 addition & 1 deletion gee-rpc/doc/geerpc-day1.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ var DefaultOption = &Option{
}
```

一般来说,涉及协议协商的这部分信息,需要设计固定的字节来传输的。但是为了实现上更简单,GeeRPC 客户端固定采用 JSON 编码 Option,后续的 header 和 body 的编码方式由 Option 中的 CodeType 指定,服务端首先使用 JSON 解码 Option,然后通过 Option CodeType 解码剩余的内容。即报文将以这样的形式发送:
一般来说,涉及协议协商的这部分信息,需要设计固定的字节来传输的。但是为了实现上更简单,GeeRPC 客户端固定采用 JSON 编码 Option,后续的 header 和 body 的编码方式由 Option 中的 CodeType 指定,服务端首先使用 JSON 解码 Option,然后通过 Option CodeType 解码剩余的内容。即报文将以这样的形式发送:

```bash
| Option{MagicNumber: xxx, CodecType: xxx} | Header{ServiceMethod ...} | Body interface{} |
Expand Down