idn - ActiveState ActiveGo 1.8
...

Package idn

import "github.com/miekg/dns/idn"
Overview
Index
Examples

Overview ▾

Package idn implements encoding from and to punycode as speficied by RFC 3492.

func FromPunycode

func FromPunycode(s string) string

FromPunycode returns unicode domain name from provided punycode string. This function expects punycode strings in lowercase.

Example

Code:

name := "xn--mgbaja8a1hpac.xn--mgbachtv"
fmt.Printf("%s -> %s", name, idn.FromPunycode(name))

Output:

xn--mgbaja8a1hpac.xn--mgbachtv -> الانترنت.اختبار

func ToPunycode

func ToPunycode(s string) string

ToPunycode converts unicode domain names to DNS-appropriate punycode names. This function will return an empty string result for domain names with invalid unicode strings. This function expects domain names in lowercase.

Example

Code:

name := "インターネット.テスト"
fmt.Printf("%s -> %s", name, idn.ToPunycode(name))

Output:

インターネット.テスト -> xn--eckucmux0ukc.xn--zckzah