Skip to content

Commit

Permalink
add setUserAgent for Client and producer
Browse files Browse the repository at this point in the history
  • Loading branch information
huolang committed May 13, 2022
1 parent cc465dc commit 20b3328
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ func convertLocked(c *Client, projName string) *LogProject {
return p
}

// SetUserAgent set a custom userAgent
func (c *Client) SetUserAgent(userAgent string) {
c.UserAgent = userAgent
}

// SetHTTPClient set a custom http client, all request will send to sls by this client
func (c *Client) SetHTTPClient(client *http.Client) {
c.HTTPClient = client
Expand Down
2 changes: 2 additions & 0 deletions client_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func CreateTokenAutoUpdateClient(endpoint string, tokenUpdateFunc UpdateTokenFun

// ClientInterface for all log's open api
type ClientInterface interface {
// SetUserAgent set userAgent for sls client
SetUserAgent(userAgent string)
// SetHTTPClient set a custom http client, all request will send to sls by this client
SetHTTPClient(client *http.Client)
// #################### Client Operations #####################
Expand Down
3 changes: 3 additions & 0 deletions producer/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func InitProducer(producerConfig *ProducerConfig) *Producer {
if producerConfig.HTTPClient != nil {
client.SetHTTPClient(producerConfig.HTTPClient)
}
if producerConfig.UserAgent != "" {
client.SetUserAgent(producerConfig.UserAgent)
}
finalProducerConfig := validateProducerConfig(producerConfig)
retryQueue := initRetryQueue()
errorStatusMap := func() map[int]*string {
Expand Down
1 change: 1 addition & 0 deletions producer/producer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ProducerConfig struct {
UpdateStsToken func() (accessKeyID, accessKeySecret, securityToken string, expireTime time.Time, err error)
StsTokenShutDown chan struct{}
HTTPClient *http.Client
UserAgent string
}

func GetDefaultProducerConfig() *ProducerConfig {
Expand Down
4 changes: 4 additions & 0 deletions token_auto_update_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func (c *TokenAutoUpdateClient) processError(err error) (retry bool) {

}

func (c *TokenAutoUpdateClient) SetUserAgent(userAgent string) {
c.logClient.SetUserAgent(userAgent)
}

// SetHTTPClient set a custom http client, all request will send to sls by this client
func (c *TokenAutoUpdateClient) SetHTTPClient(client *http.Client) {
c.logClient.SetHTTPClient(client)
Expand Down

0 comments on commit 20b3328

Please sign in to comment.