in transport/http.go [453:509]
func (t *HTTPTransport) WatchConfig(ctx context.Context, args apmconfig.WatchParams) <-chan apmconfig.Change {
changes := make(chan apmconfig.Change)
go func() {
defer close(changes)
var etag string
var out chan apmconfig.Change
var change apmconfig.Change
timer := time.NewTimer(0)
for {
select {
case <-ctx.Done():
return
case out <- change:
out = nil
change = apmconfig.Change{}
continue
case <-timer.C:
}
urlIndex := atomic.LoadInt32(&t.urlIndex)
query := make(url.Values)
query.Set("service.name", args.Service.Name)
if args.Service.Environment != "" {
query.Set("service.environment", args.Service.Environment)
}
url := *t.configURLs[urlIndex]
url.RawQuery = query.Encode()
req := t.newRequest("GET", &url)
req.Header = t.configHeaders
if etag != "" {
req.Header = copyHeaders(req.Header)
req.Header.Set("If-None-Match", strconv.QuoteToASCII(etag))
}
req = requestWithContext(ctx, req)
resp := t.configRequest(req)
var send bool
if resp.err != nil {
// The request will have failed if the context has been
// cancelled. No need to send a a change in this case.
send = ctx.Err() == nil
}
if !send && resp.attrs != nil {
etag = resp.etag
send = true
}
if send {
change = apmconfig.Change{Err: resp.err, Attrs: resp.attrs}
out = changes
}
timer.Reset(resp.maxAge)
}
}()
return changes
}