github.com/newrelic/go-agent@v3.26.0+incompatible/internal/utilization/fqdn.go (about) 1 // Copyright 2020 New Relic Corporation. All rights reserved. 2 // SPDX-License-Identifier: Apache-2.0 3 4 // +build go1.8 5 6 package utilization 7 8 import ( 9 "context" 10 "net" 11 "strings" 12 ) 13 14 func lookupAddr(addr string) ([]string, error) { 15 ctx, cancel := context.WithTimeout(context.Background(), lookupAddrTimeout) 16 defer cancel() 17 18 r := &net.Resolver{} 19 20 return r.LookupAddr(ctx, addr) 21 } 22 23 func getFQDN(candidateIPs []string) string { 24 for _, ip := range candidateIPs { 25 names, _ := lookupAddr(ip) 26 if len(names) > 0 { 27 return strings.TrimSuffix(names[0], ".") 28 } 29 } 30 return "" 31 }