isdomain

package module
Version: v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: MIT Imports: 2 Imported by: 32

README

go-is-domain

This package is dedicated to @whyrusleeping.

Docs: https://godoc.org/github.com/jbenet/go-is-domain

Check whether something is a domain.


import (
  isd "github.com/jbenet/go-is-domain"
)

isd.IsDomain("foo.com") // true
isd.IsDomain("foo.bar.com.") // true
isd.IsDomain("foo.bar.baz") // false

MIT Licensed

Updating TLDs

To update non-extended TLDs, IANA publishes, you can retrieve them from data.iana.org.

After retrieving the updated list, enter them into the file tlds-alpha-by-domain.txt. In order to update the TLDs map in tlds.go, you can run the gen.sh script which will generate the contents of a string -> bool map. After that, you'll want to replace the contents of the existing TLDs map, with the one that was generated and stored in formatted_tlds.txt

Documentation

Overview

Package isdomain package allows users to check whether strings represent domain names.

import (
	isd "github.com/jbenet/go-is-domain"
)

isd.IsDomain("foo.com") // true
isd.IsDomain("foo.bar.com.") // true
isd.IsDomain("foo.bar.baz") // false

Index

Constants

View Source
const DomainRegexpStr = "^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*$"

DomainRegexpStr is a regular expression string to validate domains.

Variables

View Source
var ExtendedTLDs = map[string]bool{
	"BIT":    true,
	"ONION":  true,
	"ETH":    true,
	"CRYPTO": true,
	"ZIL":    true,
	"BBS":    true,
	"CHAN":   true,
	"CYB":    true,
	"DYN":    true,
	"EPIC":   true,
	"GEEK":   true,
	"GOPHER": true,
	"INDY":   true,
	"LIBRE":  true,
	"NEO":    true,
	"NULL":   true,
	"O":      true,
	"OSS":    true,
	"OZ":     true,
	"PARODY": true,
	"PIRATE": true,
}

ExtendedTLDs is a set of additional "TLDs", allowing decentralized name systems, like TOR and Namecoin.

View Source
var TLDs = map[string]bool{}/* 1513 elements not displayed */

# Version 2020051300, Last Updated Wed May 13 07:07:01 2020 UTC

Functions

func IsDomain

func IsDomain(s string) bool

IsDomain returns whether given string is a domain. It first checks the TLD, and then uses a regular expression.

func IsExtendedTLD

func IsExtendedTLD(s string) bool

IsExtendedTLD returns whether the given string is a TLD (Top Level Domain), extended with a few other "TLDs": .bit, .onion

func IsICANNTLD

func IsICANNTLD(s string) bool

IsICANNTLD returns whether the given string is a TLD (Top Level Domain), according to ICANN. Well, really according to the TLDs listed in this package.

func IsTLD

func IsTLD(s string) bool

IsTLD returns whether the given string is a TLD (according to ICANN, or in the set of ExtendedTLDs listed in this package.

Types

This section is empty.

Jump to

Keyboard shortcuts

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