domainutil

package module
v0.0.0-...-13a8294 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: MIT Imports: 2 Imported by: 0

README

go-domain

Go Reference

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Domain

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.

Example
fmt.Println(Domain("google.co.uk"))
fmt.Println(Domain("keep.google.com"))
Output:

google.co.uk
google.com

func DomainPrefix

func DomainPrefix(url string) string

DomainPrefix returns second-level domain from provided url. If no SLD is found in provided url, this function returns empty string.

func DomainSuffix

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.

Example
fmt.Println(DomainSuffix("google.co.uk"))
fmt.Println(DomainSuffix("keep.google.com"))
Output:

co.uk
com

func HasSubdomain

func HasSubdomain(domain string) bool

HasSubdomain reports whether domain contains any subdomain.

Example
fmt.Println(HasSubdomain("google.com"))
fmt.Println(HasSubdomain("keep.google.com"))
Output:

false
true

func Password

func Password(url string) string

Password returns password from given url

If password is not present - return empty string

Example
fmt.Printf("%q\n", Password("user:pass@google.com"))
fmt.Printf("%q\n", Password("https://user:pass@google.com"))
fmt.Printf("%q\n", Password("https://user@google.com"))
fmt.Printf("%q\n", Password("https://google.com"))
fmt.Printf("%q\n", Password("google.com"))
Output:

"pass"
"pass"
""
""
""

func Protocol

func Protocol(url string) string

Protocol returns protocol from given url

If protocol is not present - return empty string

Example
fmt.Printf("%q\n", Protocol("google.com"))
fmt.Printf("%q\n", Protocol("ftp://google.com"))
fmt.Printf("%q\n", Protocol("http://google.com"))
fmt.Printf("%q\n", Protocol("https://google.com"))
fmt.Printf("%q\n", Protocol("https://user@google.com"))
fmt.Printf("%q\n", Protocol("https://user:pass@google.com"))
Output:

""
"ftp"
"http"
"https"
"https"
"https"

func SplitDomain

func SplitDomain(url string) []string

SplitDomain split domain into string array for example, zh.wikipedia.org will split into {"zh", "wikipedia", "org"}

func Subdomain

func Subdomain(url string) string

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

Example
fmt.Printf("%q %q", Subdomain("google.com"), Subdomain("keep.google.com"))
Output:

"" "keep"

func Username

func Username(url string) string

Username returns username from given url

If username is not present - return empty string

Example
fmt.Printf("%q\n", Username("user:pass@google.com"))
fmt.Printf("%q\n", Username("https://user:pass@google.com"))
fmt.Printf("%q\n", Username("https://user@google.com"))
fmt.Printf("%q\n", Username("https://google.com"))
fmt.Printf("%q\n", Username("google.com"))
Output:

"user"
"user"
"user"
""
""

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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