mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-11 22:00:25 +08:00
支持HTTPS的API节点
This commit is contained in:
@@ -2,6 +2,7 @@ package rpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
@@ -12,7 +13,9 @@ import (
|
|||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/rands"
|
"github.com/iwind/TeaGo/rands"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,7 +31,20 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
|||||||
|
|
||||||
conns := []*grpc.ClientConn{}
|
conns := []*grpc.ClientConn{}
|
||||||
for _, endpoint := range apiConfig.RPC.Endpoints {
|
for _, endpoint := range apiConfig.RPC.Endpoints {
|
||||||
conn, err := grpc.Dial(endpoint, grpc.WithInsecure())
|
u, err := url.Parse(endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("parse endpoint failed: " + err.Error())
|
||||||
|
}
|
||||||
|
var conn *grpc.ClientConn
|
||||||
|
if u.Scheme == "http" {
|
||||||
|
conn, err = grpc.Dial(u.Host, grpc.WithInsecure())
|
||||||
|
} else if u.Scheme == "https" {
|
||||||
|
conn, err = grpc.Dial(u.Host, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
})))
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("parse endpoint failed: invalid scheme '" + u.Scheme + "'")
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user