-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f657da
commit 5a1067a
Showing
7 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package rpc | ||
|
||
// Client 是一个 RPC 客户端的接口,该接口用于定义一个 RPC 客户端,用于发起 RPC 调用 | ||
type Client interface { | ||
// Tell 用于向指定的服务发起一个 RPC 调用,该调用不需要返回值 | ||
Tell(route Route, data any) error | ||
|
||
// Ask 用于向指定的服务发起一个 RPC 调用,该调用需要返回值 | ||
Ask(route Route, data any) (Context, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package rpc | ||
|
||
// Codec 是一个 RPC 编解码器的接口,该接口用于定义一个 RPC 编解码器,用于在 RPC 调用过程中对数据进行编解码 | ||
type Codec interface { | ||
// Encode 用于对数据进行编码 | ||
Encode(data any) ([]byte, error) | ||
|
||
// Decode 用于对数据进行解码 | ||
Decode(data []byte, dst any) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package rpc | ||
|
||
// Context 是一个 RPC 调用上下文的接口,该接口用于在 RPC 调用过程中传递上下文信息 | ||
type Context interface { | ||
// ReadTo 对于被调用方,ReadTo 方法用于将上下文信息读取到指定的结构体中 | ||
ReadTo(dst any) error | ||
|
||
// MustReadTo 对于被调用方,MustReadTo 方法用于将上下文信息读取到指定的结构体中,如果读取失败则会 panic | ||
MustReadTo(dst any) | ||
|
||
// Write 对于调用方,Write 方法用于将上下文信息写入到上下文中 | ||
Write(src any) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package rpc | ||
|
||
// Message 是一个 RPC 消息的接口,该接口用于定义一个 RPC 消息,用于在 RPC 调用过程中传递 | ||
type Message interface { | ||
// GetRoute 用于获取消息的路由 | ||
GetRoute() Route | ||
|
||
// GetBytes 用于获取消息的字节数据 | ||
GetBytes() []byte | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package rpc | ||
|
||
// Route 是一个 RPC 路由的接口,该接口用于定义一个 RPC 路由 | ||
type Route = string | ||
|
||
// RouteHandler 是一个 RPC 路由处理器的类型,该类型用于定义一个 RPC 路由处理器 | ||
type RouteHandler func(ctx Context) | ||
|
||
// Router 是 RPC 路由器的接口,该接口被用于 RPC 服务路由的注册及调用路由的匹配 | ||
type Router interface { | ||
// Register 用于注册一个 RPC 服务路由,当存在相同路由时会发生 panic | ||
Register(route Route, handler RouteHandler) | ||
|
||
// Match 用于根据 RPC 服务名匹配对应的路由处理器,如果找到则返回对应的处理器,否则返回 nil | ||
Match(route Route) RouteHandler | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters