原文: https://golang.org/doc/code.html#PackagePaths
-------------------------------------------------------------------------------------------------------------------------------------
如果demo目录下有两个文件 main.go 和mian2.go的话,main.go 和main2.go文件中的package 定义的名字要是同一个
不同的话,是会报错的。
package main import "fmt" import ( // "../demo/f1" // "./f1" ) func say() { fmt.Println("say function call!") } func main() { fmt.Println("hello, world") say() fly() // f1.F1() // f1.F2() }
main2.go
package main2 import ( "fmt" ) func fly() { fmt.Println("adada") }
main2.go 中的package main2 改为 main就是可以的。
You cannot have two packages per directory, hence the error. So the solution as @Larry Battle said to move your myproject.go
to a new directory.
From How to write go code
Go code must be kept inside a workspace. A workspace is a directory hierarchy with three directories at its root:
src contains Go source files organized into packages (one package per directory),
pkg contains package objects, and
bin contains executable commands.
原文地址:https://www.cnblogs.com/oxspirt/p/9339663.html