我有一个错误。
Document
是 goquery 库中的结构对象。
我不能在下面的代码中使用它。我该怎么办?
package main
import (
"log"
"github.com/PuerkitoBio/goquery"
"os"
)
func getLocalFile(filename string) (*Document) { // Error
f, e := os.Open(FILTER_FILE)
if e != nil {
log.Fatal(e)
}
defer f.Close()
doc, e := goquery.NewDocumentFromReader(f)
if e != nil {
log.Fatal(e)
}
return doc
}
const FILE_NAME = "input.html"
func main() {
doc := getLocalFile(FILE_NAME)
println(doc)
}
最佳答案
The Go Programming Language Specification
A qualified identifier is an identifier qualified with a package name prefix. Both the package name and the identifier must not be blank.
QualifiedIdent = PackageName "." identifier .
A qualified identifier accesses an identifier in a different package, which must be imported. The identifier must be exported and declared in the package block of that package.
math.Sin // denotes the Sin function in package math
使用完全限定名称:goquery.Document
。例如,
package main
import (
"github.com/PuerkitoBio/goquery"
"log"
"os"
)
func getLocalFile(filename string) *goquery.Document {
f, e := os.Open(filename)
if e != nil {
log.Fatal(e)
}
defer f.Close()
doc, e := goquery.NewDocumentFromReader(f)
if e != nil {
log.Fatal(e)
}
return doc
}
const FILE_NAME = "input.html"
func main() {
doc := getLocalFile(FILE_NAME)
println(doc)
}
关于go - 如何使用库对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33195072/