-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathexample_test.go
91 lines (83 loc) · 2.76 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package publicsuffix_test
import (
"fmt"
"strings"
"golang.org/x/net/publicsuffix"
)
// This example demonstrates looking up several domains' eTLDs (effective Top
// Level Domains) in the PSL (Public Suffix List) snapshot. For each eTLD, the
// example also determines whether the eTLD is ICANN managed, privately
// managed, or unmanaged (not explicitly in the PSL).
//
// See https://publicsuffix.org/ for the underlying PSL data.
func ExamplePublicSuffix_manager() {
domains := []string{
"amazon.co.uk",
"books.amazon.co.uk",
"www.books.amazon.co.uk",
"amazon.com",
"",
"example0.debian.net",
"example1.debian.org",
"",
"golang.dev",
"golang.net",
"play.golang.org",
"gophers.in.space.museum",
"",
"0emm.com",
"a.0emm.com",
"b.c.d.0emm.com",
"",
"there.is.no.such-tld",
"",
// Examples from the PublicSuffix function's documentation.
"foo.org",
"foo.co.uk",
"foo.dyndns.org",
"cromulent",
}
for _, domain := range domains {
if domain == "" {
fmt.Println(">")
continue
}
eTLD, icann := publicsuffix.PublicSuffix(domain)
// Only ICANN managed domains can have a single label. Privately
// managed domains must have multiple labels.
manager := "Unmanaged"
if icann {
manager = "ICANN Managed"
} else if strings.IndexByte(eTLD, '.') >= 0 {
manager = "Privately Managed"
}
fmt.Printf("> %24s%16s is %s\n", domain, eTLD, manager)
}
// Output:
// > amazon.co.uk co.uk is ICANN Managed
// > books.amazon.co.uk co.uk is ICANN Managed
// > www.books.amazon.co.uk co.uk is ICANN Managed
// > amazon.com com is ICANN Managed
// >
// > example0.debian.net debian.net is Privately Managed
// > example1.debian.org org is ICANN Managed
// >
// > golang.dev dev is ICANN Managed
// > golang.net net is ICANN Managed
// > play.golang.org org is ICANN Managed
// > gophers.in.space.museum museum is ICANN Managed
// >
// > 0emm.com com is ICANN Managed
// > a.0emm.com a.0emm.com is Privately Managed
// > b.c.d.0emm.com d.0emm.com is Privately Managed
// >
// > there.is.no.such-tld such-tld is Unmanaged
// >
// > foo.org org is ICANN Managed
// > foo.co.uk co.uk is ICANN Managed
// > foo.dyndns.org dyndns.org is Privately Managed
// > cromulent cromulent is Unmanaged
}