Skip to content

Commit a3d86de

Browse files
Merge pull request #210 from linode/api-version
update client to work for v4beta API
2 parents 3332b2a + 69975b4 commit a3d86de

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

cloud/linode/client/client.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ package client
44

55
import (
66
"context"
7-
"net/url"
8-
"regexp"
9-
"strings"
107

118
"github.com/linode/linodego"
129
)
@@ -48,30 +45,12 @@ var _ Client = (*linodego.Client)(nil)
4845
// New creates a new linode client with a given token, userAgent, and API URL
4946
func New(token, userAgent, apiURL string) (*linodego.Client, error) {
5047
linodeClient := linodego.NewClient(nil)
51-
linodeClient.SetUserAgent(userAgent)
52-
linodeClient.SetToken(token)
53-
54-
// Validate apiURL
55-
parsedURL, err := url.Parse(apiURL)
48+
client, err := linodeClient.UseURL(apiURL)
5649
if err != nil {
5750
return nil, err
5851
}
52+
client.SetUserAgent(userAgent)
53+
client.SetToken(token)
5954

60-
validatedURL := &url.URL{
61-
Host: parsedURL.Host,
62-
Scheme: parsedURL.Scheme,
63-
}
64-
65-
linodeClient.SetBaseURL(validatedURL.String())
66-
67-
version := ""
68-
matches := regexp.MustCompile(`/v\d+`).FindAllString(parsedURL.Path, -1)
69-
70-
if len(matches) > 0 {
71-
version = strings.Trim(matches[len(matches)-1], "/")
72-
}
73-
74-
linodeClient.SetAPIVersion(version)
75-
76-
return &linodeClient, nil
55+
return client, nil
7756
}

0 commit comments

Comments
 (0)