Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Add Client.UseURL(...) method #484

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

lgarber-akamai
Copy link
Contributor

📝 Description

This PR adds a new client.UseURL(...) method that allows users to configure the scheme, host, and version of a client using a single URL.

For example:

client.UseURL("https://api.test1.linode.com/v4beta")

This is implemented in linodego as a convenience feature for projects that previously implemented this functionality manually (e.g. CCM).

✔️ How to Test

The following test steps assume you have pulled down this PR locally.

Unit Testing

make testunit

Manual Testing

  1. In a linodego sandbox environment (e.g. dx-devenv), run the following:
package main

import (
	"context"
	"github.com/linode/linodego"
	"log"
	"os"
)

func main() {
	client := linodego.NewClient(nil)
	client.SetToken(os.Getenv("LINODE_TOKEN"))

	// This is intentionally set to an invalid URL
	if _, err := client.UseURL("https://api.test1.linode.com/v4beta"); err != nil {
		log.Fatal(err)
	}

	if _, err := client.ListInstances(context.Background(), nil); err != nil {
		log.Fatal(err)
	}
}
  1. Ensure the run fails with an error similar to the following:
2024/03/28 13:17:38.300111 WARN RESTY Get "https://api.test1.linode.com/v4beta/linode/instances": dial tcp: lookup api.test1.linode.com: no such host, Attempt 1
2024/03/28 13:17:38.300217 ERROR RESTY Get "https://api.test1.linode.com/v4beta/linode/instances": dial tcp: lookup api.test1.linode.com: no such host
2024/03/28 13:17:38 [002] Get "https://api.test1.linode.com/v4beta/linode/instances": dial tcp: lookup api.test1.linode.com: no such host

@lgarber-akamai lgarber-akamai requested a review from a team as a code owner March 28, 2024 17:18
@lgarber-akamai lgarber-akamai requested review from jriddle-linode and zliang-akamai and removed request for a team March 28, 2024 17:18
Copy link
Member

@zliang-akamai zliang-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@jriddle-linode jriddle-linode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lgarber-akamai lgarber-akamai merged commit 219f13b into linode:main Mar 28, 2024
4 checks passed
@zliang-akamai zliang-akamai added the new-feature for new features in the changelog. label Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature for new features in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants