go - 使用 Go 包中的私有(private) "lowercase"函数

标签 go package

我正在尝试在我的 main 包中使用以下函数:

html.go (来自 blackfriday):

func doubleSpace(out *bytes.Buffer) {
    if out.Len() > 0 {
        out.WriteByte('\n')
    }
}

ma​​in.go:

func (options *renderer) Paragraph(out *bytes.Buffer, text func() bool) {
    marker := out.Len()
    doubleSpace(out)

    out.WriteString("<p class='custom'>")
    if !text() {
        out.Truncate(marker)
        return
    }
    out.WriteString("</p>\n")
}

我尝试了 blackfriday.doubleSpaceblackfriday.DoubleSpace 但在这三种情况下我都得到了 undefined

正确的做法是什么?

最佳答案

你不能。这是 blackfriday 的作者深思熟虑的决定。你唯一的选择是定义你自己的函数来做同样的事情。这就像用Java这样的语言访问私有(private)成员一样。

在此处查看规范: https://golang.org/ref/spec#Exported_identifiers

关于go - 使用 Go 包中的私有(private) "lowercase"函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28778062/

相关文章:

go - 在 golang 中安装 "context"包?

go - 所有的 goroutines 都睡着了——死锁! - - - - 错误

戈朗 : How to convert string to []int?

go - 如何使用Youtube Go API获取视频信息?

javascript - 启动 Meteor 时为 "ReferenceError: Plugin is not defined"

Golang goroutine 共享 RPC 连接

mysql - 没有可用的包 mysql-server

python - Sphinx 找不到模块但 Python 可以

java - 如何通过命令行知道java包

python - 是否使用 -m 选项执行 Python 代码