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

options: Add BaseURL for clients #606

Merged
merged 1 commit into from
Mar 8, 2021
Merged

Conversation

jacobbednarz
Copy link
Member

Updates the client to be able to override the baseURL when
instantiating the client.

Use cases are generally restricted to Cloudflare employees but who knows
who else may have use for this.

Here is an example of setting up two clients and compare the output from
local and production and how we would use this.

package main

import (
	"fmt"

	"github.com/cloudflare/cloudflare-go"
)

func main() {
	local, lErr := cloudflare.New(
		"API_KEY",
		"API_EMAIL",
		cloudflare.BaseURL("https://api.test"),
	)

	prod, pErr := cloudflare.New(
		"API_KEY",
		"API_EMAIL",
	)

	if lErr != nil || pErr != nil {
		fmt.Errorf("failed to create clients")
	}

	z1, _ := local.ZoneIDByName("example.com")
	z2, _ := prod.ZoneIDByName("example.com")

	// compare the outputs
}

Updates the client to be able to override the `baseURL`[1] when
instantiating the client.

Use cases are generally restricted to Cloudflare employees but who knows
who else may have use for this.

Here is an example of setting up two clients and compare the output from
local and production and how we would use this.

```go
package main

import (
	"fmt"

	"github.com/cloudflare/cloudflare-go"
)

func main() {
	local, lErr := cloudflare.New(
		"API_KEY",
		"API_EMAIL",
		cloudflare.BaseURL("https://api.test"),
	)

	prod, pErr := cloudflare.New(
		"API_KEY",
		"API_EMAIL",
	)

	if lErr != nil || pErr != nil {
		fmt.Errorf("failed to create clients")
	}

	z1, _ := local.ZoneIDByName("example.com")
	z2, _ := prod.ZoneIDByName("example.com")

	// compare the outputs
}
```

[1]: https://github.com/cloudflare/cloudflare-go/blob/1426b776f85bc6c5c9390247d48b6ea0bcffa13f/cloudflare.go#L22
@jacobbednarz jacobbednarz merged commit 8f701f8 into master Mar 8, 2021
@jacobbednarz jacobbednarz deleted the allow-setting-base-url branch March 8, 2021 20:47
jacobbednarz added a commit to cloudflare/terraform-provider-cloudflare that referenced this pull request Oct 20, 2021
Following on from cloudflare/cloudflare-go#606, this allows the provider
to pass through the ability to override the base URL that the API client
uses for calls.
jacobbednarz added a commit to cloudflare/terraform-provider-cloudflare that referenced this pull request Oct 20, 2021
Following on from cloudflare/cloudflare-go#606, this allows the provider
to pass through the ability to override the base URL that the API client
uses for calls.
jacobbednarz added a commit to cloudflare/terraform-provider-cloudflare that referenced this pull request Oct 20, 2021
Following on from cloudflare/cloudflare-go#606, this allows the provider
to pass through the ability to override the base URL that the API client
uses for calls.
jacobbednarz added a commit to cloudflare/terraform-provider-cloudflare that referenced this pull request Oct 21, 2021
Following on from cloudflare/cloudflare-go#606, this allows the provider
to pass through the ability to override the base URL that the API client
uses for calls.
jacobbednarz added a commit to cloudflare/terraform-provider-cloudflare that referenced this pull request Oct 21, 2021
Following on from cloudflare/cloudflare-go#606, this allows the provider
to pass through the ability to override the base URL that the API client
uses for calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant