go-domain-util

module
v0.0.0-...-52a3e12 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2017 License: MIT

README

go-domain-tools

Build Status

GOlang package for checking if url contains subdomain, what that subdomain is, what is a top level domain in url etc.

Installation

go get github.com/bobesa/go-domain-util/domainutil

Rebuild the TLD database from publicsuffix.org

# (Re)build Parser
go build -o $GOPATH/bin/domainparser github.com/bobesa/go-domain-util/cmd/domainparser

# Go to domainutil pkg & generate tlds
go generate github.com/bobesa/go-domain-util/domainutil

Example code

package main

import (
    "fmt"
)

import "github.com/bobesa/go-domain-util/domainutil"

func main(){
    fmt.Println(domainutil.Domain("keep.google.com"))
}

Functions

Get the top level domain from url

func Domain(url string) string

Domain returns top level domain from url string. If no domain is found in provided url, this function returns empty string. If no TLD is found in provided url, this function returns empty string.

Get the domain suffix from url

func DomainSuffix(url string) string

DomainSuffix returns domain suffix from provided url. If no TLD is found in provided url, this function returns empty string.

Check if url has subdomain

func HasSubdomain(domain string) bool

HasSubdomain reports whether domain contains any subdomain.

Get subdomain from url

func Subdomain(url string) string

Subdomain returns subdomain from provided url. If subdomain is not found in provided url, this function returns empty string.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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