solisamicus commented on issue #2741: URL: https://github.com/apache/dubbo-go/issues/2741#issuecomment-2464903123
Description:  **解决方案:引入接口层以解耦相关包的依赖** 1. 在 clientapi 包中定义相关接口 ```go 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) } ``` 2. 在 client 包中实现上述接口 ```go 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) { // 原始实现... } // 其他方法实现... ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
