publicsuffix

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package publicsuffix implements a public suffix list to look up the organizational domain for a given host name. Organizational domains can be registered, one level below a top-level domain.

Example.com has a public suffix ".com", and example.co.uk has a public suffix ".co.uk". The organizational domain of sub.example.com is example.com, and the organization domain of sub.example.co.uk is example.co.uk.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lookup

func Lookup(ctx context.Context, elog *slog.Logger, domain dns.Domain) (orgDomain dns.Domain)

Lookup calls Lookup on the builtin public suffix list, from https://publicsuffix.org/list/.

Example
package main

import (
	"context"
	"fmt"
	"log/slog"

	"github.com/mjl-/mox/dns"
	"github.com/mjl-/mox/publicsuffix"
)

func main() {
	// Lookup the organizational domain for sub.example.org.
	orgDom := publicsuffix.Lookup(context.Background(), slog.Default(), dns.Domain{ASCII: "sub.example.org"})
	fmt.Println(orgDom)
}
Output:

example.org

Types

type List

type List struct {
	// contains filtered or unexported fields
}

List is a public suffix list.

func ParseList

func ParseList(elog *slog.Logger, r io.Reader) (List, error)

ParseList parses a public suffix list. Only the "ICANN DOMAINS" are used.

func (List) Lookup

func (l List) Lookup(ctx context.Context, elog *slog.Logger, domain dns.Domain) (orgDomain dns.Domain)

Lookup returns the organizational domain. If domain is an organizational domain, or higher-level, the same domain is returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL