在 go 中导出结构

Exporting structs in go

我有一个包含一些结构的文件:

type StructBase struct {
       // ... lots of fields
}

type Struct1 struct {
       StructBase
       // ... lots of fields
}

ImplementedStruct1 := &Struct1{
      name: "test",
      // ...
}

我在Go中了解到所有大写字母变量名都是从包中导出的。所以自然而然地 ImplementedStruct1 被导出了。但是,无论出于何种原因,我得到了

ImplementedStruct1 unexpected

我是否遗漏了一些允许我从此包导出已实现的结构对象的东西?此代码似乎与 Go 结构上的 this 教程一致。如果这很明显,我深表歉意,我一直在搜索并且对 Go 还是很陌生。谢谢!

您不能在包范围内使用 short variable declarations。您必须使用以下语法声明您的变量:

var ImplementedStruct1 = &Struct1{
      name: "test",
      // ...
}