-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from dcos/julferts/NewClient
added NewClient and default init
- Loading branch information
Showing
6 changed files
with
111 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,46 @@ | ||
package dcos | ||
|
||
import "net/http" | ||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// Client | ||
type Client struct { | ||
HttpClient *http.Client | ||
HTTPClient *http.Client | ||
Config *Config | ||
UserAgent string | ||
} | ||
|
||
// NewClient returns a Client which will detect its Config through the well | ||
// known process and use a default http.Client with DC/OS authentication. | ||
func NewClient() (*Client, error) { | ||
config, err := NewConfigManager(nil).Current() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
httpClient, err := NewHTTPClient(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
baseURL string | ||
return NewClientWithOptions(httpClient, config) | ||
} | ||
|
||
func NewClient(httpClient *http.Client) (*Client, error) { | ||
// NewClientWithOptions creates a Client from a given *http.Client and *Config | ||
func NewClientWithOptions(httpClient *http.Client, config *Config) (*Client, error) { | ||
if httpClient == nil { | ||
httpClient = http.DefaultClient | ||
return nil, fmt.Errorf("httpClient cannot be nil") | ||
} | ||
|
||
if config == nil { | ||
return nil, fmt.Errorf("config cannot be nil") | ||
} | ||
return &Client{HttpClient: httpClient}, nil | ||
|
||
return &Client{ | ||
HTTPClient: httpClient, | ||
Config: config, | ||
UserAgent: fmt.Sprintf("%s(%s)", ClientName, Version), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters