tld

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: MIT Imports: 4 Imported by: 109

README

TLD Parser in Go

GoDoc Tests

The tld package has the same API (see godoc) as net/url except tld.URL contains extra fields: Subdomain, Domain, TLD and Port.

Note: This is a wrapper around http://golang.org/x/net/publicsuffix.

Install
go get github.com/jpillora/go-tld
Usage
package main

import (
	"fmt"

	tld "github.com/jpillora/go-tld"
)

func main() {
	urls := []string{
		"http://google.com",
		"http://blog.google",
		"https://www.medi-cal.ca.gov/",
		"https://ato.gov.au",
		"http://a.very.complex-domain.co.uk:8080/foo/bar",
		"http://a.domain.that.is.unmanaged",
	}
	for _, url := range urls {
		u, _ := tld.Parse(url)
		fmt.Printf("%50s = [ %s ] [ %s ] [ %s ] [ %s ] [ %s ] [ %t ]\n",
			u, u.Subdomain, u.Domain, u.TLD, u.Port, u.Path, u.ICANN)
	}
}
$ go run main.go
                                 http://google.com = [  ] [ google ] [ com ] [  ] [  ] [ true ]
                                http://blog.google = [  ] [ blog ] [ google ] [  ] [  ] [ true ]
                      https://www.medi-cal.ca.gov/ = [ www.medi-cal ] [ ca ] [ gov ] [  ] [ / ] [ true ]
                                https://ato.gov.au = [  ] [ ato ] [ gov.au ] [  ] [  ] [ true ]
   http://a.very.complex-domain.co.uk:8080/foo/bar = [ a.very ] [ complex-domain ] [ co.uk ] [ 8080 ] [ /foo/bar ] [ true ]
                 http://a.domain.that.is.unmanaged = [ a.domain.that ] [ is ] [ unmanaged ] [  ] [  ] [ false ]
MIT License

Copyright © 2019 Jaime Pillora <dev@jpillora.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package tld has the same API as net/url except tld.URL contains extra fields: Subdomain, Domain, TLD and Port.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type URL

type URL struct {
	Subdomain, Domain, TLD, Port string
	ICANN                        bool
	*url.URL
}

URL embeds net/url and adds extra fields ontop

func Parse

func Parse(s string) (*URL, error)

Parse mirrors net/url.Parse except instead it returns a tld.URL, which contains extra fields.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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