summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/hashicorp/go-sockaddr/template/template.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/go-sockaddr/template/template.go')
-rw-r--r--vendor/github.com/hashicorp/go-sockaddr/template/template.go32
1 files changed, 31 insertions, 1 deletions
diff --git a/vendor/github.com/hashicorp/go-sockaddr/template/template.go b/vendor/github.com/hashicorp/go-sockaddr/template/template.go
index ffe467b7f..bbed51361 100644
--- a/vendor/github.com/hashicorp/go-sockaddr/template/template.go
+++ b/vendor/github.com/hashicorp/go-sockaddr/template/template.go
@@ -64,23 +64,53 @@ func init() {
HelperFuncs = template.FuncMap{
// Misc functions that operate on IfAddrs inputs
- "attr": sockaddr.IfAttr,
+ "attr": Attr,
"join": sockaddr.JoinIfAddrs,
"limit": sockaddr.LimitIfAddrs,
"offset": sockaddr.OffsetIfAddrs,
"unique": sockaddr.UniqueIfAddrsBy,
+ // Misc math functions that operate on a single IfAddr input
+ "math": sockaddr.IfAddrsMath,
+
// Return a Private RFC 6890 IP address string that is attached
// to the default route and a forwardable address.
"GetPrivateIP": sockaddr.GetPrivateIP,
+ // Return all Private RFC 6890 IP addresses as a space-delimited string of
+ // IP addresses. Addresses returned do not have to be on the interface with
+ // a default route.
+ "GetPrivateIPs": sockaddr.GetPrivateIPs,
+
// Return a Public RFC 6890 IP address string that is attached
// to the default route and a forwardable address.
"GetPublicIP": sockaddr.GetPublicIP,
+ // Return allPublic RFC 6890 IP addresses as a space-delimited string of IP
+ // addresses. Addresses returned do not have to be on the interface with a
+ // default route.
+ "GetPublicIPs": sockaddr.GetPublicIPs,
+
// Return the first IP address of the named interface, sorted by
// the largest network size.
"GetInterfaceIP": sockaddr.GetInterfaceIP,
+
+ // Return all IP addresses on the named interface, sorted by the largest
+ // network size.
+ "GetInterfaceIPs": sockaddr.GetInterfaceIPs,
+ }
+}
+
+// Attr returns the attribute from the ifAddrRaw argument. If the argument is
+// an IfAddrs, only the first element will be evaluated for resolution.
+func Attr(selectorName string, ifAddrsRaw interface{}) (string, error) {
+ switch v := ifAddrsRaw.(type) {
+ case sockaddr.IfAddr:
+ return sockaddr.IfAttr(selectorName, v)
+ case sockaddr.IfAddrs:
+ return sockaddr.IfAttrs(selectorName, v)
+ default:
+ return "", fmt.Errorf("unable to obtain attribute %s from type %T (%v)", selectorName, ifAddrsRaw, ifAddrsRaw)
}
}