1 回答
TA贡献1866条经验 获得超5个赞
PublicFunction使用PublicStruct其私有字段将是私有的私有文档。例如,
package godocprivate
type PublicInterface interface {
PublicFunction()
}
type privatestruct struct {
}
// PublicStruct is something to be documented except for private fields
type PublicStruct struct {
privatestruct
}
func NewPublic() *PublicStruct {
ps := &PublicStruct{}
return ps
}
// PublicFunction does something to be documented
func (p *PublicStruct) PublicFunction() {
}
当PublicStruct被创建它最初具有用于每个场的零个值。如果这还不够,请引入工厂布尔值。例如,
package godocprivate
type PublicInterface interface {
PublicFunction()
}
type privatestruct struct {
}
// PublicStruct is something to be documented except for private fields
type PublicStruct struct {
factory bool
privatestruct
}
func NewPublic() *PublicStruct {
ps := &PublicStruct{factory: true}
return ps
}
// PublicFunction does something to be documented
func (p *PublicStruct) PublicFunction() {
if !p.factory {
panic("Use NewPublic")
}
}
- 1 回答
- 0 关注
- 171 浏览
添加回答
举报