1package dns_test
2
3import (
4 "fmt"
5 "log"
6
7 "github.com/mjl-/mox/dns"
8)
9
10func ExampleParseDomain() {
11 // ASCII-only domain.
12 basic, err := dns.ParseDomain("example.com")
13 if err != nil {
14 log.Fatalf("parse domain: %v", err)
15 }
16 fmt.Printf("%s\n", basic)
17
18 // IDNA domain xn--74h.example.
19 smile, err := dns.ParseDomain("☺.example")
20 if err != nil {
21 log.Fatalf("parse domain: %v", err)
22 }
23 fmt.Printf("%s\n", smile)
24
25 // ASCII only domain curl.se in surprisingly allowed spelling.
26 surprising, err := dns.ParseDomain("ℂᵤⓇℒ。𝐒🄴")
27 if err != nil {
28 log.Fatalf("parse domain: %v", err)
29 }
30 fmt.Printf("%s\n", surprising)
31
32 // Output:
33 // example.com
34 // ☺.example/xn--74h.example
35 // curl.se
36}
37