英文:
How can I use library object?
问题
我有一个错误。
Document
是 goquery 库中的结构对象。
我无法在下面的代码中使用它。我该怎么办?
package main
import (
"log"
"github.com/PuerkitoBio/goquery"
"os"
)
func getLocalFile(filename string) (*Document) { // 错误
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)
}
英文:
I have an error.
Document
is struct object on goquery library.
I can't use it in my code below. How can I do?
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)
}
答案1
得分: 4
《Go编程语言规范》
限定标识符
限定标识符是带有包名前缀的标识符。包名和标识符都不能是空白。
QualifiedIdent = PackageName "." identifier
限定标识符用于访问不同包中的标识符,该包必须被导入。该标识符必须是被导出的,并且在该包的包块中声明。
math.Sin // 表示math包中的Sin函数
使用完全限定名称: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)
}
英文:
> The Go Programming Language Specification
>
> Qualified identifiers
>
> 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
Use the fully qualified name: goquery.Document
. For example,
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)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论