I'm trying to make a simple calculator in Go. I'm designing it in such a way that I can build a command-line interface first and easily swap in a GUI interface. The project location is $GOPATH/src/gocalc
(all paths hereafter are relative to the project location). The command-line interface logic is stored in a file gocalc.go
. The calculator logic is stored in files calcfns/calcfns.go
and operations/operations.go
. All files have package names identical to their filename (sans extension) except the main program, gocalc.go
, which is in the package main
calcfns.go
imports operations.go
via import "gocalc/operations"
; gocalc.go
imports calcfns.go
via import "gocalc/calcfns"
To summarize:
$GOPATH/src/gocalc/
gocalc.go
package main
import "gocalc/calcfns"
calcfns/
calcfns.go
package calcfns
import "gocalc/operations"
operations/
operations.go
package operations
When I try to go build operations
(from the project dir), I get the response: can't load package: package operations: import "operations": cannot find package
When I try go build gocalc/operations
, I get can't load package: package gocalc/operations: import "gocalc/operations": cannot find package
When I try go build operations/operations.go
, it compiles fine
When I try to go build calcfns
or go build gocalc/calcfns
, I get can't load package...
messages, similar to those in operations; however, when I try to build calcfns/calcfns.go
it chokes on the import statement: import "gocalc/operations": cannot find package
Finally, when I try go build .
from the project dir, it chokes similar to the previous paragraph: import "gocalc/calcfns": cannot find package
How should I structure my child packages and/or import statements in such a way that go build
won't fail?