hostname

package
v3.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package hostname splits host:port values and converts IDN host names.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitPort

func SplitPort(authority string) (host, port string)

SplitPort splits "host[:port]" into host and port without trimming. A bracketed IPv6 literal keeps its brackets and ends at the first ']', and anything after it but a ":port" is dropped. A value with several colons is returned whole as a bare IPv6 literal. An unclosed '[' is not a literal, so "[a:80" splits like any other host into "[a" and "80".

func ToASCII

func ToASCII(host string) string

ToASCII converts a non-ASCII host to Punycode. IDNA has no concept of a port, so a caller holding "host:port" splits it first: a host with a colon is returned unchanged. So are an ASCII host and one idna.Lookup rejects, so an invalid host fails by not matching.

func ToUnicode

func ToUnicode(host string) string

ToUnicode decodes the Punycode labels of host. "xn--" anywhere in host sends all of it through idna.Lookup, which also maps the other labels (width, dots, soft hyphens), and a single label it rejects leaves the whole host unchanged. The xn-- check is case-sensitive, so callers fold ASCII case first.

Types

This section is empty.

Jump to

Keyboard shortcuts

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