net functions

net.LookupIP

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

Note: Unresolvable hostnames will result in an error, and gomplate will panic.

Usage

net.LookupIP name

Arguments

name description
name 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.

Note: Unresolvable hostnames will result in an error, and gomplate will panic.

Usage

net.LookupIPs name

Arguments

name description
name 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.".

Note: Unresolvable hostnames will result in an error, and gomplate will panic.

Usage

net.LookupCNAME name

Arguments

name description
name 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

Note: Unresolvable hostnames will result in an error, and gomplate will panic.

Usage

net.LookupSRV name

Arguments

name description
name 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

Note: Unresolvable hostnames will result in an error, and gomplate will panic.

Usage

net.LookupSRVs name

Arguments

name description
name The service name to look up

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.

Note: Unresolvable hostnames will result in an error, and gomplate will panic.

Usage

net.LookupTXT name

Arguments

name description
name The host name to look up

Examples

$ gomplate -i '{{net.LookupTXT "example.com" | toJSONPretty "\t" }}'
[
	"$Id: example.com 4415 2015-08-24 20:12:23Z davids $",
	"v=spf1 -all"
]