n5

module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT

README

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.

Directories

Path Synopsis
Package domain provides helper functions for managing domain names
Package domain provides helper functions for managing domain names
Package http provides helper functions for http protocol
Package http provides helper functions for http protocol
Package ip provides helper functions for IP addresses
Package ip provides helper functions for IP addresses
Package url provides helper functions for URLs
Package url provides helper functions for URLs
Package validate provides helper functions for validating various network resources
Package validate provides helper functions for validating various network resources

Jump to

Keyboard shortcuts

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