Skip to content

Commit

Permalink
Add support for configurable User-Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Apr 6, 2024
1 parent 2694f0e commit 9a3b3d3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion apstra/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type ClientCfg struct {
Timeout time.Duration // <0 = infinite; 0 = DefaultTimeout; >0 = this value is used
ErrChan chan<- error // async client errors (apstra task polling, etc) sent here
Experimental bool // used to enable experimental features
UserAgent string // may used to set a custom user-agent
}

// TaskId represents outstanding tasks on an Apstra server
Expand Down Expand Up @@ -205,11 +206,16 @@ func (o ClientCfg) NewClient(ctx context.Context) (*Client, error) {
httpClient = &http.Client{}
}

httpHeaders := map[string]string{"Accept": "application/json"}
if o.UserAgent != "" {
httpHeaders["User-Agent"] = o.UserAgent
}

c := &Client{
cfg: o,
baseUrl: baseUrl,
httpClient: httpClient,
httpHeaders: map[string]string{"Accept": "application/json"},
httpHeaders: httpHeaders,
logger: logger,
taskMonChan: make(chan *taskMonitorMonReq),
sync: make(map[string]*sync.Mutex),
Expand Down

0 comments on commit 9a3b3d3

Please sign in to comment.