Source files of the same package can refer to identifiers defined in any of the source files without any effort. If they are in the same folder and if they have the same package declaration, you can refer all package-level exported and unexported identifiers as if all would have been defined in one file.
See Spec: Packages:
A package in turn is constructed from one or more source files that together declare constants, types, variables and functions belonging to the package and which are accessible in all files of the same package.
And Spec: Package clause:
A set of files sharing the same PackageName form the implementation of a package. An implementation may require that all source files for a package inhabit the same directory.
One thing to note: your example seems to be the special main
package. If you want to run it with go run
, you have to enumerate all the source files.
To run your example with go run
, navigate to the gddo-server
folder and type:
go run background.go browse.go client.go crawl.go graph.go main.go play.go template.go
Or simpler if you first build it. Navigate to the gddo-server
folder and type:
go build
This will generate a native executable binary in the same folder. To run it type: gddo-server
(on Windows) or ./gddo-server
(on Linux).
Or you can install it with go install
which will place the result executable binary in your $GOPATH/bin
folder.