I am using below code for an API to find ip address for a given domain:
func IPFinder(c *gin.Context) {
var domain models.Domain
c.BindJSON(&domain)
addr, err := net.LookupIP(domain.DomainName)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
} else {
c.JSON(http.StatusOK, gin.H{"ip_address": addr})
}
return
}
For the below request:
{
"domain_name": "yahoo.com"
}
getting response as :
{
"ip_address": [
"2404:6800:4002:80a::200e",
"172.217.167.46"
]
}
Here this LookupIP method is giving the slice containing ipv4 and ipv6 address of that domain. Is there any other way of any other 3rd party lib in GoLang using which I can get output containing only the ip address like below :
{
"ip_address": "172.217.167.46"
}