Documentation ¶
Index ¶
- type DefaultResolver
- type MxResp
- type Resolver
- func (r Resolver) LookupAddress(ip string) ([]string, error)
- func (r Resolver) LookupCNAME(fqdn string) (string, error)
- func (r Resolver) LookupMX(fqdn string) ([]*MxResp, error)
- func (r Resolver) LookupTXT(fqdn string) ([]string, error)
- func (r Resolver) Reroute(address, network string) error
- func (r Resolver) Reset() error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultResolver ¶
type DefaultResolver interface { LookupTXT(name string) ([]string, error) LookupAddress(name string) ([]string, error) LookupCNAME(name string) (string, error) LookupMX(name string) ([]*MxResp, error) Reroute(address, network string) error Reset() error }
func NewResolver ¶
func NewResolver() (DefaultResolver, error)
NewResolver creates and uses a default resolver
Example ¶
package main import ( "fmt" symbols "bitbucket.org/taubyte/go-sdk-symbols/dns" "bitbucket.org/taubyte/go-sdk/dns" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.MockNew(5) resolver, err := dns.NewResolver() if err != nil { return } fmt.Printf("%d\n", resolver) }
Output: 5
type Resolver ¶
type Resolver uint32
Example ¶
package main import ( "fmt" symbols "bitbucket.org/taubyte/go-sdk-symbols/dns" "bitbucket.org/taubyte/go-sdk/dns" "bitbucket.org/taubyte/go-sdk/event" ) func dnsFunction(e event.Event) uint32 { resolver, err := dns.NewResolver() if err != nil { return 1 } values, err := resolver.LookupAddress("8.8.8.8") if err != nil { return 1 } fmt.Println("Address:", values) value, err := resolver.LookupCNAME("taubyte.com.") if err != nil { return 1 } fmt.Println("CNAME:", value) mxValues, err := resolver.LookupMX("google.com") if err != nil { return 1 } fmt.Println("MX:", mxValues[0].Host, mxValues[0].Pref) values, err = resolver.LookupTXT("google.com") if err != nil { return 1 } fmt.Println("TxT:", values[0]) err = resolver.Reroute("8.8.8.8:53", "udp") if err != nil { return 1 } err = resolver.Reset() if err != nil { return 1 } return 0 } func main() { // Mocking the calls to the vm for usage in tests and playground symbols.MockData{Id: 5, TxtData: map[string][]byte{ "google.com": symbols.Convert([]string{ "MS=15412F62916164C0B20BB", "verification=J9cpOJM0nikft0jAgjmsQ", }), }, AddressData: map[string][]byte{ "8.8.8.8": symbols.Convert([]string{ "dns.google", }), }, CnameData: map[string][]byte{ "taubyte.com.": symbols.Convert([]string{ "nodes.taubyte.com.", }), }, MxData: map[string][]byte{ "google.com": []byte("smtp.google.com.\x00/10\x00"), }, }.Mock() e := dnsFunction(0) if e > 0 { fmt.Println(e) return } fmt.Println("Success") }
Output: Address: [dns.google] CNAME: nodes.taubyte.com. MX: smtp.google.com. 10 TxT: MS=15412F62916164C0B20BB Success
func (Resolver) LookupAddress ¶
LookupAddr performs a reverse lookup for the given address, returning a list of names mapping to that address and an error.
Example ¶
package main import ( "fmt" symbols "bitbucket.org/taubyte/go-sdk-symbols/dns" "bitbucket.org/taubyte/go-sdk/dns" ) func main() { // Mocking the calls to the vm for usage in tests and playground testData := map[string][]byte{ "8.8.8.8": symbols.Convert([]string{ "dns.google", }), } symbols.MockData{AddressData: testData}.Mock() r, err := dns.NewResolver() if err != nil { return } values, err := r.LookupAddress("8.8.8.8") if err != nil { return } fmt.Println(values[0]) }
Output: dns.google
func (Resolver) LookupCNAME ¶
LookupCNAME returns the canonical name for the given host.
LookupCNAME does not return an error if the given name does not contain DNS "CNAME" records, as long as the name resolves to address records.
Example ¶
package main import ( "fmt" symbols "bitbucket.org/taubyte/go-sdk-symbols/dns" "bitbucket.org/taubyte/go-sdk/dns" ) func main() { // Mocking the calls to the vm for usage in tests and playground testData := map[string][]byte{ "taubyte.com.": symbols.Convert([]string{ "nodes.taubyte.com.", }), } symbols.MockData{CnameData: testData}.Mock() r, err := dns.NewResolver() if err != nil { return } values, err := r.LookupCNAME("taubyte.com.") if err != nil { return } fmt.Println(values) }
Output: nodes.taubyte.com.
func (Resolver) LookupMX ¶
LookupMX returns the DNS MX records for the given name and an error.
Example ¶
package main import ( "fmt" symbols "bitbucket.org/taubyte/go-sdk-symbols/dns" "bitbucket.org/taubyte/go-sdk/dns" ) func main() { // Mocking the calls to the vm for usage in tests and playground testData := map[string][]byte{ "google.com": []byte("smtp.google.com.\x00/10\x00"), } symbols.MockData{MxData: testData}.Mock() r, err := dns.NewResolver() if err != nil { return } values, err := r.LookupMX("google.com") if err != nil { return } fmt.Println(values[0].Host, values[0].Pref) }
Output: smtp.google.com. 10
func (Resolver) LookupTXT ¶
LookupTXT returns the DNS TXT records for the given domain name.
Example ¶
package main import ( "fmt" symbols "bitbucket.org/taubyte/go-sdk-symbols/dns" "bitbucket.org/taubyte/go-sdk/dns" ) func main() { // Mocking the calls to the vm for usage in tests and playground testData := map[string][]byte{ "google.com": symbols.Convert([]string{ "MS=15412F62916164C0B20BB", "verification=J9cpOJM0nikft0jAgjmsQ", }), } symbols.MockData{TxtData: testData}.Mock() r, err := dns.NewResolver() if err != nil { return } values, err := r.LookupTXT("google.com") if err != nil { return } fmt.Println(values[0]) }
Output: MS=15412F62916164C0B20BB
func (Resolver) Reroute ¶ added in v0.1.27
Reroute reroutes the resolver to the provided address and network Return an error
Example ¶
package main import ( "fmt" symbols "bitbucket.org/taubyte/go-sdk-symbols/dns" "bitbucket.org/taubyte/go-sdk/dns" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.MockNew(0) symbols.MockReroute(0, "8.8.8.8:53", "udp") r, err := dns.NewResolver() if err != nil { return } err = r.Reroute("8.8.8.8:53", "udp") if err != nil { return } fmt.Println("Success") }
Output: Success
func (Resolver) Reset ¶ added in v0.1.27
Reset sets the current resolver to the default provided resolver Returns an error
Example ¶
package main import ( "fmt" symbols "bitbucket.org/taubyte/go-sdk-symbols/dns" "bitbucket.org/taubyte/go-sdk/dns" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.MockData{}.Mock() r, err := dns.NewResolver() if err != nil { return } err = r.Reset() if err != nil { return } fmt.Println("Success") }
Output: Success