Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hakluke/tldextract
Extract root domain, subdomain name, and tld from a url, using the Public Suffix List.
https://github.com/hakluke/tldextract
Last synced: about 2 months ago
JSON representation
Extract root domain, subdomain name, and tld from a url, using the Public Suffix List.
- Host: GitHub
- URL: https://github.com/hakluke/tldextract
- Owner: hakluke
- Fork: true (joeguo/tldextract)
- Created: 2021-08-09T12:25:34.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-11T18:26:10.000Z (over 2 years ago)
- Last Synced: 2024-07-27T02:35:12.576Z (about 2 months ago)
- Language: Go
- Homepage:
- Size: 26.4 KB
- Stars: 8
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
tldextract
==========Extract root domain, subdomain name, tld from a url, using the [IANA TLD list](https://data.iana.org/TLD/tlds-alpha-by-domain.txt).
This is a modified version of https://github.com/joeguo/tldextract which uses the [public suffix](https://www.publicsuffix.org/) list of TLDs.
Installation
==========
Install tldextract:
```sh
go get github.com/joeguo/tldextract```
To run unit tests, run this command in tldextract's source directory($GOPATH/src/github.com/joeguo/tldextract):```sh
go test
```Example
==========
```go
package mainimport (
"fmt"
"github.com/joeguo/tldextract"
)func main() {
urls := []string{"git+ssh://www.github.com:8443/", "http://media.forums.theregister.co.uk", "http://218.15.32.76", "http://google.com?q=cats"}
cache := "/tmp/tld.cache"
extract, _ := tldextract.New(cache,false)for _, u := range (urls) {
result:=extract.Extract(u)
fmt.Printf("%+v;%s\n",result,u)
}
}```
Output will look like:
```plain
&{Flag:1 Sub:www Root:github Tld:com};git+ssh://www.github.com:8443/
&{Flag:1 Sub:media.forums Root:theregister Tld:co.uk};http://media.forums.theregister.co.uk
&{Flag:2 Sub: Root:218.15.32.76 Tld:};http://218.15.32.76
&{Flag:1 Sub: Root:google Tld:com};http://google.com?q=cats
```
Flag value meaning
```go
const (
Malformed = iota
Domain
Ip4
Ip6
)
```========