go - 同一包中的功能可见性

标签 go

如果我理解正确的话——一个包的所有源文件都在同一个范围内。

我有两个文件 - room.go:

package main

func newRoom() *room {
    return &room{
        forward: make(chan []byte),
        join:    make(chan *client),
        leave:   make(chan *client),
        clients: make(map[*client]bool),
        tracer:  trace.Off(),
    }
}

main.go:

package main

func main() {    
    r := newRoom()

当我编译代码时出现错误:

.\main.go:34: undefined: newRoom

为什么?

完整代码在这里https://github.com/matryer/goblueprints/tree/master/chapter1/chat

最佳答案

go run *.go 将在类 unix 系统中运行,在 Windows 中尝试列出 main 包中的所有文件

关于go - 同一包中的功能可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45662612/

相关文章:

go - viper yaml 配置序列

import - 有没有办法稍后在golang中导入?

无序字符串集的良好哈希函数?

go - 如何强制 VSCode 在 goimports 匹配多个同名包的情况下需要手动选择?

scala - Scala 是否有等同于 golangs 的延迟?

go - 为什么在 runtime.GOMAXPROCS(1) 时单个 goroutine 比多个 goroutine 运行得慢?

go - 在 Go 编程中使用 golang-Debian 包

go - Go 中的 strconv.Atoi(基本计算器)

go - 如何制作 goreleaser 脚本以在本地构建 deb 文件?

go - 在 Ubuntu Precise 上安装 snap