net functions

net.LookupIP

Resolve an IPv4 address for a given host name. When multiple IP addresses are resolved, the first one is returned.

Usage

net.LookupIP name
name | net.LookupIP

Arguments

name description
name (required) The hostname to look up. This can be a simple hostname, or a fully-qualified domain name.

Examples

$ gomplate -i '{{ net.LookupIP "example.com" }}'
93.184.216.34

net.LookupIPs

Resolve all IPv4 addresses for a given host name. Returns an array of strings.

Usage

net.LookupIPs name
name | net.LookupIPs

Arguments

name description
name (required) The hostname to look up. This can be a simple hostname, or a fully-qualified domain name.

Examples

$ gomplate -i '{{ join (net.LookupIPs "twitter.com") "," }}'
104.244.42.65,104.244.42.193

net.LookupCNAME

Resolve the canonical name for a given host name. This does a DNS lookup for the CNAME record type. If no CNAME is present, a canonical form of the given name is returned – e.g. net.LookupCNAME "localhost" will return "localhost.".

Usage

net.LookupCNAME name
name | net.LookupCNAME

Arguments

name description
name (required) The hostname to look up. This can be a simple hostname, or a fully-qualified domain name.

Examples

$ gomplate -i '{{ net.LookupCNAME "www.amazon.com" }}'
d3ag4hukkh62yn.cloudfront.net.

net.LookupSRV

Resolve a DNS SRV service record. This implementation supports the canonical RFC2782 form (i.e. _Service._Proto.Name), but other forms are also supported, such as those served by Consul’s DNS interface.

When multiple records are returned, this function returns the first.

A net.SRV data structure is returned. The following properties are available: - Target - (string) the hostname where the service can be reached - Port - (uint16) the service’s port - Priority, Weight - see RFC2782 for details

Usage

net.LookupSRV name
name | net.LookupSRV

Arguments

name description
name (required) The service name to look up

Examples

$ gomplate -i '{{ net.LookupSRV "_sip._udp.sip.voice.google.com" | toJSONPretty "  " }}'
{
  "Port": 5060,
  "Priority": 10,
  "Target": "sip-anycast-1.voice.google.com.",
  "Weight": 1
}

net.LookupSRVs

Resolve a DNS SRV service record. This implementation supports the canonical RFC2782 form (i.e. _Service._Proto.Name), but other forms are also supported, such as those served by Consul’s DNS interface.

This function returns all available SRV records.

An array of net.SRV data structures is returned. For each element, the following properties are available: - Target - (string) the hostname where the service can be reached - Port - (uint16) the service’s port - Priority, Weight - see RFC2782 for details

Usage

net.LookupSRVs name
name | net.LookupSRVs

Arguments

name description
name (required) The hostname to look up. This can be a simple hostname, or a fully-qualified domain name.

Examples

input.tmpl:

{{ range (net.LookupSRVs "_sip._udp.sip.voice.google.com") -}}
priority={{.Priority}}/port={{.Port}}
{{- end }}
$ gomplate -f input.tmpl
priority=10/port=5060
priority=20/port=5060

net.LookupTXT

Resolve a DNS TXT record.

This function returns all available TXT records as an array of strings.

Usage

net.LookupTXT name
name | net.LookupTXT

Arguments

name description
name (required) The host name to look up

Examples

$ gomplate -i '{{net.LookupTXT "example.com" | data.ToJSONPretty "  " }}'
[
  "v=spf1 -all"
]