mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	GRPC通讯支持gzip压缩
This commit is contained in:
		@@ -17,6 +17,7 @@ import (
 | 
			
		||||
	"google.golang.org/grpc/connectivity"
 | 
			
		||||
	"google.golang.org/grpc/credentials"
 | 
			
		||||
	"google.golang.org/grpc/credentials/insecure"
 | 
			
		||||
	"google.golang.org/grpc/encoding/gzip"
 | 
			
		||||
	"google.golang.org/grpc/metadata"
 | 
			
		||||
	"net/url"
 | 
			
		||||
	"sync"
 | 
			
		||||
@@ -561,12 +562,14 @@ func (this *RPCClient) init() error {
 | 
			
		||||
			return errors.New("parse endpoint failed: " + err.Error())
 | 
			
		||||
		}
 | 
			
		||||
		var conn *grpc.ClientConn
 | 
			
		||||
		var callOptions = grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(128*1024*1024),
 | 
			
		||||
			grpc.UseCompressor(gzip.Name))
 | 
			
		||||
		if u.Scheme == "http" {
 | 
			
		||||
			conn, err = grpc.Dial(u.Host, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(128*1024*1024)))
 | 
			
		||||
			conn, err = grpc.Dial(u.Host, grpc.WithTransportCredentials(insecure.NewCredentials()), callOptions)
 | 
			
		||||
		} else if u.Scheme == "https" {
 | 
			
		||||
			conn, err = grpc.Dial(u.Host, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{
 | 
			
		||||
				InsecureSkipVerify: true,
 | 
			
		||||
			})), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(128*1024*1024)))
 | 
			
		||||
			})), callOptions)
 | 
			
		||||
		} else {
 | 
			
		||||
			return errors.New("parse endpoint failed: invalid scheme '" + u.Scheme + "'")
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user