mirror of
https://github.com/aljazceru/ark.git
synced 2026-01-31 17:14:46 +01:00
Handle tls connection with asp (#96)
This commit is contained in:
committed by
GitHub
parent
ee2a416297
commit
0d8c7bffb2
@@ -2,10 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
|
||||
"github.com/urfave/cli/v2"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
@@ -52,7 +54,17 @@ func getClientFromState(ctx *cli.Context) (arkv1.ArkServiceClient, func(), error
|
||||
}
|
||||
|
||||
func getClient(ctx *cli.Context, addr string) (arkv1.ArkServiceClient, func(), error) {
|
||||
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
creds := insecure.NewCredentials()
|
||||
port := 80
|
||||
if strings.HasPrefix(addr, "https://") {
|
||||
addr = strings.TrimPrefix(addr, "https://")
|
||||
creds = credentials.NewTLS(nil)
|
||||
port = 443
|
||||
}
|
||||
if !strings.Contains(addr, ":") {
|
||||
addr = fmt.Sprintf("%s:%d", addr, port)
|
||||
}
|
||||
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(creds))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user