Skip to content

Commit f45866a

Browse files
authored
Change host port type from net.URL to string. (#11)
1 parent fdacad8 commit f45866a

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

cloudclient/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ func New(options Options) (*Client, error) {
3333
// create a new gRPC client connection
3434
// note that the grpc.NewClient will not establish a connection to the server until the first call is made
3535
conn, err := grpc.NewClient(
36-
hostPort.String(),
36+
hostPort,
3737
grpcDialOptions...,
3838
)
3939
if err != nil {
40-
return nil, fmt.Errorf("failed to dial `%s`: %w", hostPort.String(), err)
40+
return nil, fmt.Errorf("failed to dial `%s`: %w", hostPort, err)
4141
}
4242

4343
return &Client{

cloudclient/options.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"crypto/tls"
66
"errors"
7-
"fmt"
8-
"net/url"
97
"time"
108

119
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
@@ -38,7 +36,7 @@ type Options struct {
3836

3937
// The hostport to use when connecting to the cloud operations API.
4038
// If not provided, the default hostport of `saas-api.tmprl.cloud:443` will be used.
41-
HostPort url.URL
39+
HostPort string
4240

4341
// Allow the client to connect to the cloud operations API using an insecure connection.
4442
// This should only be used for testing purposes.
@@ -83,23 +81,18 @@ func (r staticAPIKeyReader) GetAPIKey(ctx context.Context) (string, error) {
8381
}
8482

8583
func (o *Options) compute() (
86-
hostPort url.URL,
84+
hostPort string,
8785
grpcDialOptions []grpc.DialOption,
8886
err error,
8987
) {
88+
hostPort = o.HostPort
89+
if hostPort == "" {
90+
// set the default host port if not provided
91+
hostPort = defaultCloudOpsAPIHostPort
92+
}
9093

94+
// setup the grpc dial options
9195
grpcDialOptions = make([]grpc.DialOption, 0, len(o.GRPCDialOptions)+4)
92-
// set the default host port if not provided
93-
if o.HostPort.String() == "" {
94-
var defaultHostPort *url.URL
95-
defaultHostPort, err = url.Parse(defaultCloudOpsAPIHostPort)
96-
if err != nil {
97-
return url.URL{}, nil, fmt.Errorf("failed to parse default host port: %w", err)
98-
}
99-
hostPort = *defaultHostPort
100-
} else {
101-
hostPort = o.HostPort
102-
}
10396

10497
var transport credentials.TransportCredentials
10598
// setup the transport
@@ -115,7 +108,7 @@ func (o *Options) compute() (
115108
)
116109

117110
if o.APIKey != "" && o.APIKeyReader != nil {
118-
return url.URL{}, nil, errors.New("only one of APIKey and APIKeyReader can be provided")
111+
return "", nil, errors.New("only one of APIKey and APIKeyReader can be provided")
119112
}
120113
// setup the api key credentials
121114
creds := apikeyCreds{
@@ -127,7 +120,7 @@ func (o *Options) compute() (
127120
creds.reader = o.APIKeyReader
128121
}
129122
if creds.reader == nil {
130-
return url.URL{}, nil, errors.New("either APIKey or APIKeyReader must be provided")
123+
return "", nil, errors.New("either APIKey or APIKeyReader must be provided")
131124
} else {
132125
grpcDialOptions = append(grpcDialOptions,
133126
grpc.WithPerRPCCredentials(creds),

0 commit comments

Comments
 (0)