-
Notifications
You must be signed in to change notification settings - Fork 931
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
Package dependency optimization #2741
Comments
FoghostCn
changed the title
【task】Package dependency optimization
Package dependency optimization
Nov 4, 2024
解决方案:引入接口层以解耦相关包的依赖
package clientapi
import ...
// ConnectionInterface:将 Connection 的功能抽象成接口
type ConnectionInterface interface {
CallUnary(ctx context.Context, reqs []interface{}, resp interface{}, methodName string, opts ...CallOption) error
CallClientStream(ctx context.Context, methodName string, opts ...CallOption) (interface{}, error)
CallServerStream(ctx context.Context, req interface{}, methodName string, opts ...CallOption) (interface{}, error)
CallBidiStream(ctx context.Context, methodName string, opts ...CallOption) (interface{}, error)
}
// ClientInterface:将 Client 的功能抽象成接口
type ClientInterface interface {
Dial(interfaceName string, opts ...ReferenceOption) (ConnectionInterface, error)
DialWithInfo(interfaceName string, info *ClientInfo, opts ...ReferenceOption) (ConnectionInterface, error)
DialWithDefinition(interfaceName string, definition *ClientDefinition, opts ...ReferenceOption) (ConnectionInterface, error)
}
package client
import ...
// 确保 Connection 实现了 clientapi.ConnectionInterface 接口
func (conn *Connection) CallUnary(ctx context.Context, reqs []interface{}, resp interface{}, methodName string, opts ...CallOption) error {
// 原始实现...
}
// 其他方法实现...
// 确保 Client 实现了 clientapi.ClientInterface 接口
func (cli *Client) Dial(interfaceName string, opts ...ReferenceOption) (clientiface.ConnectionInterface, error) {
// 原始实现...
}
// 其他方法实现... |
有些依赖可能是不必要的,甚至是错误的,需要先梳理一下模块的依赖关系再决定要怎么去解决,有些可以用接口解决,有些需要挪动一些代码 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: