Skip to content

Commit

Permalink
add another tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
miekg committed Mar 23, 2013
1 parent 0229c88 commit b8ac344
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
23 changes: 23 additions & 0 deletions tutorial1/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

// https://www.unbound.net/documentation/libunbound-tutorial-1.html

import (
"fmt"
"github.com/miekg/unbound"
"log"
)

func main() {
u := unbound.New()
defer u.Destroy()

addr, err := u.LookupHost("wwww.nlnetlabs.nl")
if err != nil {
log.Fatalf("error %s\n", err.Error())
}

for _, a := range addr {
fmt.Printf("The address is %s\n", a)
}
}
11 changes: 4 additions & 7 deletions tutorial2/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,23 @@ import (
"fmt"
"github.com/miekg/dns"
"github.com/miekg/unbound"
"os"
"log"
)

func main() {
u := unbound.New()
defer u.Destroy()

if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
fmt.Printf("error %s\n", err.Error())
os.Exit(1)
log.Fatalf("error %s\n", err.Error())
}

if err := u.Hosts("/etc/hosts"); err != nil {
fmt.Printf("error %s\n", err.Error())
os.Exit(1)
log.Fatalf("error %s\n", err.Error())
}
r, err := u.Resolve("www.nlnetlabs.nl.", dns.TypeA, dns.ClassINET)
if err != nil {
fmt.Printf("error %s\n", err.Error())
os.Exit(1)
log.Fatalf("error %s\n", err.Error())
}
fmt.Printf("%+v\n", r)
}

0 comments on commit b8ac344

Please sign in to comment.