github.com/hairyhenderson/templater@v3.5.0+incompatible/funcs/net.go (about) 1 package funcs 2 3 import ( 4 stdnet "net" 5 "sync" 6 7 "github.com/hairyhenderson/gomplate/conv" 8 9 "github.com/hairyhenderson/gomplate/net" 10 ) 11 12 var ( 13 netNS *NetFuncs 14 netNSInit sync.Once 15 ) 16 17 // NetNS - the net namespace 18 func NetNS() *NetFuncs { 19 netNSInit.Do(func() { netNS = &NetFuncs{} }) 20 return netNS 21 } 22 23 // AddNetFuncs - 24 func AddNetFuncs(f map[string]interface{}) { 25 f["net"] = NetNS 26 } 27 28 // NetFuncs - 29 type NetFuncs struct{} 30 31 // LookupIP - 32 func (f *NetFuncs) LookupIP(name interface{}) (string, error) { 33 return net.LookupIP(conv.ToString(name)) 34 } 35 36 // LookupIPs - 37 func (f *NetFuncs) LookupIPs(name interface{}) ([]string, error) { 38 return net.LookupIPs(conv.ToString(name)) 39 } 40 41 // LookupCNAME - 42 func (f *NetFuncs) LookupCNAME(name interface{}) (string, error) { 43 return net.LookupCNAME(conv.ToString(name)) 44 } 45 46 // LookupSRV - 47 func (f *NetFuncs) LookupSRV(name interface{}) (*stdnet.SRV, error) { 48 return net.LookupSRV(conv.ToString(name)) 49 } 50 51 // LookupSRVs - 52 func (f *NetFuncs) LookupSRVs(name interface{}) ([]*stdnet.SRV, error) { 53 return net.LookupSRVs(conv.ToString(name)) 54 } 55 56 // LookupTXT - 57 func (f *NetFuncs) LookupTXT(name interface{}) ([]string, error) { 58 return net.LookupTXT(conv.ToString(name)) 59 }