Skip to content

Commit 9fd2355

Browse files
feat(client): add support for reading base URL from environment variable
1 parent 6cc0281 commit 9fd2355

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

client.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,23 @@ type Client struct {
2222
Storage *StorageService
2323
}
2424

25-
// DefaultClientOptions read from the environment (OPENLAYER_API_KEY). This should
26-
// be used to initialize new clients.
25+
// DefaultClientOptions read from the environment (OPENLAYER_API_KEY,
26+
// OPENLAYER_BASE_URL). This should be used to initialize new clients.
2727
func DefaultClientOptions() []option.RequestOption {
2828
defaults := []option.RequestOption{option.WithEnvironmentProduction()}
29+
if o, ok := os.LookupEnv("OPENLAYER_BASE_URL"); ok {
30+
defaults = append(defaults, option.WithBaseURL(o))
31+
}
2932
if o, ok := os.LookupEnv("OPENLAYER_API_KEY"); ok {
3033
defaults = append(defaults, option.WithAPIKey(o))
3134
}
3235
return defaults
3336
}
3437

3538
// NewClient generates a new client with the default option read from the
36-
// environment (OPENLAYER_API_KEY). The option passed in as arguments are applied
37-
// after these default arguments, and all option will be passed down to the
38-
// services and requests that this client makes.
39+
// environment (OPENLAYER_API_KEY, OPENLAYER_BASE_URL). The option passed in as
40+
// arguments are applied after these default arguments, and all option will be
41+
// passed down to the services and requests that this client makes.
3942
func NewClient(opts ...option.RequestOption) (r *Client) {
4043
opts = append(DefaultClientOptions(), opts...)
4144

0 commit comments

Comments
 (0)