feat(auth): 连接docreader支持auth

This commit is contained in:
Li Xianggang
2026-05-16 17:49:31 +08:00
committed by lyingbug
parent c87e35b34b
commit 5a02e22f52
9 changed files with 363 additions and 26 deletions
+15 -8
View File
@@ -9,7 +9,6 @@ import (
"github.com/Tencent/WeKnora/docreader/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/resolver"
)
@@ -40,17 +39,25 @@ type Client struct {
}
func NewClient(addr string) (*Client, error) {
authConfig := LoadAuthConfigFromEnv()
return NewClientWithAuth(addr, authConfig)
}
func NewClientWithAuth(addr string, authConfig *AuthConfig) (*Client, error) {
Logger.Printf("INFO: Creating new DocReader client connecting to %s", addr)
maxMsgSize := getMaxMessageSize()
opts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`),
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(maxMsgSize),
grpc.MaxCallSendMsgSize(maxMsgSize),
),
if authConfig == nil {
authConfig = &AuthConfig{}
}
opts, err := authConfig.BuildDialOptions(maxMsgSize)
if err != nil {
Logger.Printf("ERROR: Failed to build dial options: %v", err)
return nil, err
}
resolver.SetDefaultScheme("dns")
startTime := time.Now()