rootdomain

package module
v0.0.0-...-abfb450 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: MIT Imports: 13 Imported by: 0

README

rootdomain

Extract root domain, subdomain name, tld from a url, using the the Public Suffix List.

Installation

Install rootdomain:

go get github.com/AYM1607/rootdomain

To run unit tests, run this command in rootdomains's source:

go test

Example

package main

import (
	"fmt"
	"github.com/AYM1607/rootdomain"
)


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, _ := rootdomain.New(cache,false)

	for _, u := range (urls) {
		result:=extract.Extract(u)
		fmt.Printf("%+v;%s\n",result,u)
	}
}

Output will look like:

  &{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

const (
	Malformed = iota
	Domain
	Ip4
	Ip6
)

========

Documentation

Overview

Package rootdomain provides the ability to extract gTLD or ccTLD(generic or country code top-level domain), the registered domain and subdomain from a url according to the Public Suffix List.

A simple usage:

package main

import (

"fmt"

"github.com/AYM1607/rootdomain"

)

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 := rootdomain.New(cache,false)

	for _, u := range (urls) {
		result:=extract.Extract(u)
		fmt.Printf("%+v;%s\n",result,u)
	}
}

Index

Constants

View Source
const (
	Malformed = iota
	Domain
)

used for Result.Flag

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

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

func (*Result) GetRootDomain

func (r *Result) GetRootDomain() string

func (*Result) GetSubDomain

func (r *Result) GetSubDomain() string

func (*Result) GetTopLevelDomain

func (r *Result) GetTopLevelDomain() string

type TLDExtract

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

func New

func New(debug bool) (*TLDExtract, error)

New creates a new *TLDExtract, it may be shared between goroutines, we usually need a single instance in an application.

func (*TLDExtract) Extract

func (e *TLDExtract) Extract(u string) (*Result, error)

type Trie

type Trie struct {
	ExceptRule bool
	ValidTld   bool
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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