File: example_test.go

package info (click to toggle)
golang-golang-x-net 1%3A0.27.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 8,636 kB
  • sloc: asm: 18; makefile: 12; sh: 7
file content (95 lines) | stat: -rw-r--r-- 2,955 bytes parent folder | download
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
92
93
94
95
// 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"
	"testing"

	"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(t *testing.T) {
	t.SkipNow()
	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",
		"foo.blogspot.co.uk",
		"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
	// >       foo.blogspot.co.uk  blogspot.co.uk  is  Privately Managed
	// >                cromulent       cromulent  is  Unmanaged
}