github.com/wuhuizuo/gomplate@v3.5.0+incompatible/docs/content/functions/net.md (about) 1 --- 2 title: net functions 3 menu: 4 main: 5 parent: functions 6 --- 7 8 9 ## `net.LookupIP` 10 11 Resolve an IPv4 address for a given host name. When multiple IP addresses 12 are resolved, the first one is returned. 13 14 ### Usage 15 16 ```go 17 net.LookupIP name 18 ``` 19 ```go 20 name | net.LookupIP 21 ``` 22 23 ### Arguments 24 25 | name | description | 26 |------|-------------| 27 | `name` | _(required)_ The hostname to look up. This can be a simple hostname, or a fully-qualified domain name. | 28 29 ### Examples 30 31 ```console 32 $ gomplate -i '{{ net.LookupIP "example.com" }}' 33 93.184.216.34 34 ``` 35 36 ## `net.LookupIPs` 37 38 Resolve all IPv4 addresses for a given host name. Returns an array of strings. 39 40 ### Usage 41 42 ```go 43 net.LookupIPs name 44 ``` 45 ```go 46 name | net.LookupIPs 47 ``` 48 49 ### Arguments 50 51 | name | description | 52 |------|-------------| 53 | `name` | _(required)_ The hostname to look up. This can be a simple hostname, or a fully-qualified domain name. | 54 55 ### Examples 56 57 ```console 58 $ gomplate -i '{{ join (net.LookupIPs "twitter.com") "," }}' 59 104.244.42.65,104.244.42.193 60 ``` 61 62 ## `net.LookupCNAME` 63 64 Resolve the canonical name for a given host name. This does a DNS lookup for the 65 `CNAME` record type. If no `CNAME` is present, a canonical form of the given name 66 is returned -- e.g. `net.LookupCNAME "localhost"` will return `"localhost."`. 67 68 ### Usage 69 70 ```go 71 net.LookupCNAME name 72 ``` 73 ```go 74 name | net.LookupCNAME 75 ``` 76 77 ### Arguments 78 79 | name | description | 80 |------|-------------| 81 | `name` | _(required)_ The hostname to look up. This can be a simple hostname, or a fully-qualified domain name. | 82 83 ### Examples 84 85 ```console 86 $ gomplate -i '{{ net.LookupCNAME "www.amazon.com" }}' 87 d3ag4hukkh62yn.cloudfront.net. 88 ``` 89 90 ## `net.LookupSRV` 91 92 Resolve a DNS [`SRV` service record](https://en.wikipedia.org/wiki/SRV_record). 93 This implementation supports the canonical [RFC2782](https://tools.ietf.org/html/rfc2782) 94 form (i.e. `_Service._Proto.Name`), but other forms are also supported, such as 95 those served by [Consul's DNS interface](https://www.consul.io/docs/agent/dns.html#standard-lookup). 96 97 When multiple records are returned, this function returns the first. 98 99 A [`net.SRV`](https://golang.org/pkg/net/#SRV) data structure is returned. The 100 following properties are available: 101 - `Target` - _(string)_ the hostname where the service can be reached 102 - `Port` - _(uint16)_ the service's port 103 - `Priority`, `Weight` - see [RFC2782](https://tools.ietf.org/html/rfc2782) for details 104 105 ### Usage 106 107 ```go 108 net.LookupSRV name 109 ``` 110 ```go 111 name | net.LookupSRV 112 ``` 113 114 ### Arguments 115 116 | name | description | 117 |------|-------------| 118 | `name` | _(required)_ The service name to look up | 119 120 ### Examples 121 122 ```console 123 $ gomplate -i '{{ net.LookupSRV "_sip._udp.sip.voice.google.com" | toJSONPretty " " }}' 124 { 125 "Port": 5060, 126 "Priority": 10, 127 "Target": "sip-anycast-1.voice.google.com.", 128 "Weight": 1 129 } 130 ``` 131 132 ## `net.LookupSRVs` 133 134 Resolve a DNS [`SRV` service record](https://en.wikipedia.org/wiki/SRV_record). 135 This implementation supports the canonical [RFC2782](https://tools.ietf.org/html/rfc2782) 136 form (i.e. `_Service._Proto.Name`), but other forms are also supported, such as 137 those served by [Consul's DNS interface](https://www.consul.io/docs/agent/dns.html#standard-lookup). 138 139 This function returns all available SRV records. 140 141 An array of [`net.SRV`](https://golang.org/pkg/net/#SRV) data structures is 142 returned. For each element, the following properties are available: 143 - `Target` - _(string)_ the hostname where the service can be reached 144 - `Port` - _(uint16)_ the service's port 145 - `Priority`, `Weight` - see [RFC2782](https://tools.ietf.org/html/rfc2782) for details 146 147 ### Usage 148 149 ```go 150 net.LookupSRVs name 151 ``` 152 ```go 153 name | net.LookupSRVs 154 ``` 155 156 ### Arguments 157 158 | name | description | 159 |------|-------------| 160 | `name` | _(required)_ The hostname to look up. This can be a simple hostname, or a fully-qualified domain name. | 161 162 ### Examples 163 164 _input.tmpl:_ 165 ``` 166 {{ range (net.LookupSRVs "_sip._udp.sip.voice.google.com") -}} 167 priority={{.Priority}}/port={{.Port}} 168 {{- end }} 169 ``` 170 171 ```console 172 $ gomplate -f input.tmpl 173 priority=10/port=5060 174 priority=20/port=5060 175 ``` 176 177 ## `net.LookupTXT` 178 179 Resolve a DNS [`TXT` record](https://en.wikipedia.org/wiki/SRV_record). 180 181 This function returns all available TXT records as an array of strings. 182 183 ### Usage 184 185 ```go 186 net.LookupTXT name 187 ``` 188 ```go 189 name | net.LookupTXT 190 ``` 191 192 ### Arguments 193 194 | name | description | 195 |------|-------------| 196 | `name` | _(required)_ The host name to look up | 197 198 ### Examples 199 200 ```console 201 $ gomplate -i '{{net.LookupTXT "example.com" | data.ToJSONPretty " " }}' 202 [ 203 "v=spf1 -all" 204 ] 205 ```