Skip to content

AndrewDonelson/gotld

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gotld

Build Status GitHub last commit Coverage Status Codacy Badge GoDoc GitHub stars

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 was been written using the Google Public Suffix package

Install

go get github.com/AndrewDonelson/gotld

Usage

package main

import (
	"fmt"

	"github.com/AndrewDonelson/gotld"
)

func main() {
	urls := []string{
		"nlaak.com",			//	net/url bug - returns as path. Workaround add scheme
		"https://nlaak.com",	//	net/url this works :(
		"http://go.com?foo=bar",
		"http://google.com",
		"http://blog.google",
		"https://www.medi-cal.ca.gov/",
		"https://ato.gov.au",
		"http://stage.host.domain.co.uk/",
		"http://a.very.complex-domain.co.uk:8080/foo/bar",
	}

	println("Example #1")
	for _, url := range urls {
		u, _ := tld.FQDNMgr.GetFQDN(url)
		fmt.Printf("%47s = fqdn[%s]\n", url, u)
	}
}
$ go run main.go
Example #1
                                      nlaak.com = fqdn[nlaak.com]
                              https://nlaak.com = fqdn[nlaak.com]
                          http://go.com?foo=bar = fqdn[go.com]
                              http://google.com = fqdn[google.com]
                             http://blog.google = fqdn[blog.google]
                   https://www.medi-cal.ca.gov/ = fqdn[ca.gov]
                             https://ato.gov.au = fqdn[ato.gov.au]
                http://stage.host.domain.co.uk/ = fqdn[domain.co.uk]
http://a.very.complex-domain.co.uk:8080/foo/bar = fqdn[complex-domain.co.uk]

MIT License

Copyright © 2020 Andrew Donelson <[email protected]>

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published