Skip to content

Commit

Permalink
Merge pull request #58 from ovh/dev/rbeuque/user-agent
Browse files Browse the repository at this point in the history
feat(user-agent): allow User-Agent personnalisation
  • Loading branch information
rbeuque74 authored Sep 14, 2022
2 parents 63d8ee5 + 571f18c commit 655254e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ovh/ovh.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ type Client struct {

// Timeout configures the maximum duration to wait for an API requests to complete
Timeout time.Duration

// UserAgent configures the user-agent indication that will be sent in the requests to OVHcloud API
UserAgent string
}

// NewClient represents a new client to call the API
Expand Down Expand Up @@ -309,7 +312,11 @@ func (c *Client) NewRequest(method, path string, reqBody interface{}, needAuth b
// Send the request with requested timeout
c.Client.Timeout = c.Timeout

req.Header.Set("User-Agent", "github.com/ovh/go-ovh")
if c.UserAgent != "" {
req.Header.Set("User-Agent", "github.com/ovh/go-ovh ("+c.UserAgent+")")
} else {
req.Header.Set("User-Agent", "github.com/ovh/go-ovh")
}

return req, nil
}
Expand Down

0 comments on commit 655254e

Please sign in to comment.