Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Url 在Golang中如何将punycode转换为unicode?_Url_Go_Unicode_Import_Package - Fatal编程技术网

Url 在Golang中如何将punycode转换为unicode?

Url 在Golang中如何将punycode转换为unicode?,url,go,unicode,import,package,Url,Go,Unicode,Import,Package,我想转换url f.e.: xn--h1aaebtrh5b.xn--p1ai-->чччччч 当然,反过来说: 克里姆林宫.ru->xn--d1abbgf6aiy.xn--p1ai 我尝试使用idna包,但无法导入供应商包idna 关于文件: 尝试导入: import "golang_org/x/net/idna" 获取错误: main.go:18:8: cannot find package "golang_org/x/net/idna" in any of: /usr/loca

我想转换url f.e.:

xn--h1aaebtrh5b.xn--p1ai-->чччччч

当然,反过来说:

克里姆林宫.ru->xn--d1abbgf6aiy.xn--p1ai

我尝试使用idna包,但无法导入供应商包idna

关于文件:

尝试导入:

import "golang_org/x/net/idna"
获取错误:

main.go:18:8: cannot find package "golang_org/x/net/idna" in any of:
    /usr/local/go/src/golang_org/x/net/idna (from $GOROOT)
    /home/arseny/go/src/golang_org/x/net/idna (from $GOPATH)
另一种尝试:

import "vendor/golang_org/x/net/idna"
错误:

main.go:18:8: must be imported as golang_org/x/net/idna

main.go:19:2: use of vendored package not allowed

有人说这个代码有效

在bash中:

go get golang.org/x/net/idna
示例代码go:

package main

import (
    "fmt"
    "golang.org/x/net/idna"
)

var p *idna.Profile

func main() {
    // Raw Punycode has no restrictions and does no mappings.
    p = idna.New()
    fmt.Println(p.ToUnicode("xn--d1abbgf6aiiy.xn--p1ai"))
}

但我仍然希望有另一种方式存在。我不喜欢将包的本地副本复制到$GOROOT路径中。

有人说这段代码可以工作

在bash中:

go get golang.org/x/net/idna
示例代码go:

package main

import (
    "fmt"
    "golang.org/x/net/idna"
)

var p *idna.Profile

func main() {
    // Raw Punycode has no restrictions and does no mappings.
    p = idna.New()
    fmt.Println(p.ToUnicode("xn--d1abbgf6aiiy.xn--p1ai"))
}

但我仍然希望有另一种方式存在。我不想将包本地复制到$GOROOT路径。

为什么要导入
golang_org/x/net/idna
?该包名为
golang.org/x/net/idna
。是和否,在IDE Goglang中,此文件夹名为golang\u orgwhy-1???奇怪的人。。。。。。js中的相同假设这个问题并不是关于如何将punycode转换为unicode。这是关于为什么你不能导入那个包。您已经知道如何转换punycode,如您的问题所示。真的吗??好的,在开始的时候,我说我想要什么,我使用google并找到它的软件包,接下来我真的不能导入它们,但是如果你知道如何将punycode转换为unicode和reverse,我会非常感激。你为什么要导入
golang_org/x/net/idna
?该包名为
golang.org/x/net/idna
。是和否,在IDE Goglang中,此文件夹名为golang\u orgwhy-1???奇怪的人。。。。。。js中的相同假设这个问题并不是关于如何将punycode转换为unicode。这是关于为什么你不能导入那个包。您已经知道如何转换punycode,如您的问题所示。真的吗??好的,在开始的时候,我想说什么就说什么,我使用google并找到它的软件包,接下来我真的无法导入它们,但是如果你知道如何将punycode转换为unicode和reverse,我会非常感激。