mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-06 15:01:28 +02:00
[management] rest client with options
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
type Client struct {
|
||||
managementURL string
|
||||
authHeader string
|
||||
httpClient *http.Client
|
||||
|
||||
// Accounts NetBird account APIs
|
||||
// see more: https://docs.netbird.io/api/resources/accounts
|
||||
@@ -69,21 +70,33 @@ type Client struct {
|
||||
}
|
||||
|
||||
// New initialize new Client instance using PAT token
|
||||
func New(managementURL, token string) *Client {
|
||||
func New(managementURL, token string, opts ...option) *Client {
|
||||
client := &Client{
|
||||
managementURL: managementURL,
|
||||
authHeader: "Token " + token,
|
||||
httpClient: http.DefaultClient,
|
||||
}
|
||||
|
||||
for _, option := range opts {
|
||||
option(client)
|
||||
}
|
||||
|
||||
client.initialize()
|
||||
return client
|
||||
}
|
||||
|
||||
// NewWithBearerToken initialize new Client instance using Bearer token type
|
||||
func NewWithBearerToken(managementURL, token string) *Client {
|
||||
func NewWithBearerToken(managementURL, token string, opts ...option) *Client {
|
||||
client := &Client{
|
||||
managementURL: managementURL,
|
||||
authHeader: "Bearer " + token,
|
||||
httpClient: http.DefaultClient,
|
||||
}
|
||||
|
||||
for _, option := range opts {
|
||||
option(client)
|
||||
}
|
||||
|
||||
client.initialize()
|
||||
return client
|
||||
}
|
||||
|
||||
11
management/client/rest/options.go
Normal file
11
management/client/rest/options.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package rest
|
||||
|
||||
import "net/http"
|
||||
|
||||
type option func(*Client)
|
||||
|
||||
func WithHttpClient(client *http.Client) option {
|
||||
return func(c *Client) {
|
||||
c.httpClient = client
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user