mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-26 09:57:23 +03:00
* F #3952: Change GOCA NewClient for HTTP client Now supports the use of a custom HTTP client. If the httpClient == nil, the function will return a NewDefaultClient that, still, uses the cleanhttp.DefaultPooledClient() * F #3952: Update GOCA examples to NewDefaultClient
This commit is contained in:
parent
e1ff1d4f2a
commit
a7932813b9
@ -16,7 +16,7 @@ func main() {
|
||||
|
||||
// Create first client on the floating ip to
|
||||
// retrieve the global zone informations
|
||||
client := goca.NewClient(conf)
|
||||
client := goca.NewDefaultClient(conf)
|
||||
controller := goca.NewController(client)
|
||||
|
||||
// Retrieve the id of the zone
|
||||
@ -37,7 +37,7 @@ func main() {
|
||||
|
||||
// Create a client
|
||||
conf.Endpoint = server.Endpoint
|
||||
client = goca.NewClient(conf)
|
||||
client = goca.NewDefaultClient(conf)
|
||||
|
||||
// Pass it to the controller
|
||||
controller.Client = client
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := goca.NewClient(
|
||||
client := goca.NewDefaultClient(
|
||||
goca.NewConfig("", "", ""),
|
||||
)
|
||||
controller := goca.NewController(client)
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := goca.NewClient(
|
||||
client := goca.NewDefaultClient(
|
||||
goca.NewConfig("", "", ""),
|
||||
)
|
||||
controller := goca.NewController(client)
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := goca.NewClient(
|
||||
client := goca.NewDefaultClient(
|
||||
goca.NewConfig("", "", ""),
|
||||
)
|
||||
controller := goca.NewController(client)
|
||||
|
@ -92,8 +92,8 @@ func NewConfig(user string, password string, endpoint string) OneConfig {
|
||||
return config
|
||||
}
|
||||
|
||||
// NewClient return a new basic one client
|
||||
func NewClient(conf OneConfig) *Client {
|
||||
// NewDefaultClient return a new basic one client
|
||||
func NewDefaultClient(conf OneConfig) *Client {
|
||||
return &Client{
|
||||
url: conf.Endpoint,
|
||||
token: conf.Token,
|
||||
@ -101,6 +101,19 @@ func NewClient(conf OneConfig) *Client {
|
||||
}
|
||||
}
|
||||
|
||||
// NewClient return a new one client that allows setting a custom http.Client.
|
||||
// If the httpClient is nil, it will return a NewDefaultClient
|
||||
func NewClient(conf OneConfig, httpClient *http.Client) *Client {
|
||||
if httpClient == nil {
|
||||
return NewDefaultClient(conf)
|
||||
}
|
||||
return &Client{
|
||||
url: conf.Endpoint,
|
||||
token: conf.Token,
|
||||
httpClient: httpClient,
|
||||
}
|
||||
}
|
||||
|
||||
// Call is an XML-RPC wrapper. It returns a pointer to response and an error.
|
||||
func (c *Client) Call(method string, args ...interface{}) (*Response, error) {
|
||||
var (
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var testClient = NewClient(NewConfig("", "", ""))
|
||||
var testClient = NewDefaultClient(NewConfig("", "", ""))
|
||||
var testCtrl = NewController(testClient)
|
||||
|
||||
// Appends a random string to a name
|
||||
|
Loading…
x
Reference in New Issue
Block a user