in internal/source/gitlab/client/client.go [103:144]
func (gc *Client) GetLookup(ctx context.Context, host string) api.Lookup {
params := url.Values{}
params.Set("host", host)
if err := ValidateHostName(host); err != nil {
log.WithError(err).WithFields(
log.Fields{
"correlation_id": correlation.ExtractFromContext(ctx),
"lookup_name": host,
}).Error()
return api.Lookup{Name: host, Error: domain.ErrDomainDoesNotExist}
}
resp, err := gc.get(ctx, "/api/v4/internal/pages", params)
if err != nil {
metrics.DomainsSourceFailures.Inc()
return api.Lookup{Name: host, Error: err}
}
if resp == nil {
log.WithError(domain.ErrDomainDoesNotExist).WithFields(
log.Fields{
"correlation_id": correlation.ExtractFromContext(ctx),
"lookup_name": host,
}).Error("unexpected nil response from gitlab")
return api.Lookup{Name: host, Error: domain.ErrDomainDoesNotExist}
}
// ensure that entire response body has been read and close it, to make it
// possible to reuse HTTP connection. In case of a JSON being invalid and
// larger than 512 bytes, the response body will not be closed properly, thus
// we need to close it manually in every case.
defer func() {
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
}()
lookup := api.Lookup{Name: host}
lookup.ParseDomain(resp.Body)
return lookup
}