|
@@ -6,12 +6,14 @@ import (
|
|
|
"errors"
|
|
|
"io"
|
|
|
"log"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
|
|
|
pb "git.mokkon.com/sainw/fho_forward_proto.git"
|
|
|
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
|
|
|
"google.golang.org/grpc"
|
|
|
"google.golang.org/grpc/codes"
|
|
|
+ "google.golang.org/grpc/credentials"
|
|
|
"google.golang.org/grpc/metadata"
|
|
|
"google.golang.org/grpc/status"
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
@@ -27,9 +29,22 @@ func NewClient(address string, id string, key string) (*FhoClient, error) {
|
|
|
opts := []grpc_retry.CallOption{
|
|
|
grpc_retry.WithBackoff(grpc_retry.BackoffLinear(100 * time.Millisecond)),
|
|
|
}
|
|
|
+ addresses := strings.Split(address, ":")
|
|
|
+ host := addresses[0]
|
|
|
+ port := ""
|
|
|
+ if len(addresses) > 1 {
|
|
|
+ port = addresses[1]
|
|
|
+ }
|
|
|
+ options := make([]grpc.DialOption, 0)
|
|
|
+ options = append(options, grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(opts...)))
|
|
|
+
|
|
|
+ if port == "443" {
|
|
|
+ options = append(options, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, host)))
|
|
|
+ } else {
|
|
|
+ options = append(options, grpc.WithInsecure())
|
|
|
+ }
|
|
|
|
|
|
- conn, err := grpc.Dial(address, grpc.WithInsecure(),
|
|
|
- grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(opts...)))
|
|
|
+ conn, err := grpc.Dial(address, options...)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|