Skip to content
/ n5 Public

Collection of network utilities for Go (Golang), such as domain names, IPs and URLs.

License

Notifications You must be signed in to change notification settings

detectify/n5

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

n5

Growing collection of network utilities for Go (Golang), such as domain names, IPs and URLs.

Go Reference build Go Report Card

Installation

To install n5, use go get:

go get github.com/detectify/n5

domain package

The domain package provides functions for managing domain names, which is represented as a sequence of labels in the type domain.Name. Supports various levels of names (up to TLD), internationalized names and names not on the public suffix list. To create a domain name, parse the string representation, or extract it from a string containing the domain name, such as a URL.

import (
    "fmt"
    "github.com/detectify/n5/domain"
)

func main() {
    name, err := domain.Parse("www.example.com")
    fmt.Println("apex = " + name.Apex()) // prints "apex = example.com"
    fmt.Println("tld = " + name.EffectiveTLD()) // prints "tld = com"
    fmt.Println("FQDN = " + name.FQDN()) // prints "tld = www.example.com."
    
    name, err = domain.Extract("https://пример.мкд/index.html")
    fmt.Println("domain (punycoded) = " + name.String()) 
       // prints "domain (punycoded) = xn--e1afmkfd.xn--d1alf"
    fmt.Println("domain (original) = " + name.Unicode()) 
       // prints "domain (original) = пример.мкд"
}

Notes

http package

The http package provides a function for validating the HTTP method (http.ValidateMethod).

ip package

The ip package provides functions for validating IP v4/v6 addresses, including cross-checking against reserved IPs. Separate functions are available for all, v4 and v6 IPs, for example ip.IsIP, ip.IsIPv4, ip.IsIPv6.

url package

The url package provides functions for validating absolute URLs (url.IsAbsolute) and extracting hostname from URL (url.Host).

Notes

  • Host extraction aims to support non-standard URL formats for which the url.URL type returns error.

Contributing

Please feel free to submit issues, fork the repository and send pull requests. In addition to fixes, new features are also welcome if you feel they are within the scope of the package. Feel free to reach out and discuss if you have any questions.

License

This project is licensed under the terms of the MIT license.

About

Collection of network utilities for Go (Golang), such as domain names, IPs and URLs.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages