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

Package dependency optimization #2741

Open
FoghostCn opened this issue Nov 4, 2024 · 3 comments
Open

Package dependency optimization #2741

FoghostCn opened this issue Nov 4, 2024 · 3 comments

Comments

@FoghostCn
Copy link
Contributor

  1. Remove all dependencies on the config package 解除所有对 config 包的依赖关系
  2. Remove all dependencies on the client/server package 解除所有对 client/server 包的依赖关系
@FoghostCn FoghostCn changed the title 【task】Package dependency optimization Package dependency optimization Nov 4, 2024
@FoghostCn FoghostCn assigned FoghostCn and unassigned FoghostCn Nov 4, 2024
@FoghostCn
Copy link
Contributor Author

@solisamicus @LQyt2012

@solisamicus
Copy link

solisamicus commented Nov 8, 2024

需求描述:
Remove all dependencies on the config-client-server package

解决方案:引入接口层以解耦相关包的依赖

  1. 在 clientapi 包中定义相关接口
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)
}
  1. 在 client 包中实现上述接口
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) {
    // 原始实现...
}

// 其他方法实现...

@FoghostCn
Copy link
Contributor Author

有些依赖可能是不必要的,甚至是错误的,需要先梳理一下模块的依赖关系再决定要怎么去解决,有些可以用接口解决,有些需要挪动一些代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants