Golang包导入

huangapple go评论66阅读模式
英文:

Golang Package Import

问题

我正在尝试编译以下代码:

package main

import (
    "fmt"    
    "code.google.com/p/go.text/unicode/norm"
)

func main() {
    fmt.Println(norm.IsNormalString("ŋ̊"))
}

我已经安装了unicode/norm包。我使用以下命令进行编译:

go build -o ipa ipa.go

不幸的是,我得到了以下错误:

# command-line-arguments
./ipa.go:9: undefined: norm.IsNormalString
make: *** [ipa] Error 2

看起来包已经被正确导入,但我无法访问任何其成员。我尝试将调用的方法更改为norm的另一个方法,但仍然出现错误。这让我相信我对Go的包系统有一些基本的误解。

英文:

I am attempting to get the following code to compile:

package main

import (
    "fmt"    
    "code.google.com/p/go.text/unicode/norm"
)

func main() {
    fmt.Println(norm.IsNormalString("ŋ̊"))
}

I have installed the unicode/norm package. I compile with the command:

go build -o ipa ipa.go

Unfortunately, I get the following error:

# command-line-arguments
./ipa.go:9: undefined: norm.IsNormalString
make: *** [ipa] Error 2

It seems that the package is being imported correctly, but I cannot access any of its members. I have tried changing the method from being called to another from norm, but I still get the error. This leads me to believe that I'm fundamentally misunderstanding something about go's package system.

答案1

得分: 1

IsNormalString不是一个函数,而是Form类型的方法。例如,

package main

import (
	"code.google.com/p/go.text/unicode/norm"
	"fmt"
)

func main() {
	fmt.Println(norm.NFC.IsNormalString("ŋ̊"))
}

输出结果为:

true
英文:

> func (Form) IsNormalString
>
> func (f Form) IsNormalString(s string) bool
>
> IsNormalString returns true if s == f(s).

IsNormalString is not a function, it's a method on type Form. For example,

package main

import (
	"code.google.com/p/go.text/unicode/norm"
	"fmt"
)

func main() {
	fmt.Println(norm.NFC.IsNormalString("ŋ̊"))
}

Output:

true

huangapple
  • 本文由 发表于 2014年11月1日 14:48:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/26686885.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定