Packages
Last updated
Was this helpful?
Last updated
Was this helpful?
Like Python
, sometimes, you want to separate your codes to different files.
So it can be organized.
In Python, you use import
to load function from .py file
.
In Golang, you will also use import
to load function from .go file
.
But Golang
file structure is different.
For exampleοΌa tree of a project may look like this:
If you run main.go
οΌyou'll get:
That tells us some facts:
golang
package was separated by folder
. In that folder, all your .go file
must declare the package name
by package *
you can import
your own packages from main.go
with ./your_package_name
before golang import any package, it will run the init()
function first
if you want to export or use a function from a package, the first character of that function name
must keep capitalizing.
Sometimes, people would like to put all their source codes to ~/go/src
In that case you will import a package using github.com/yourname/projectname
It's good to do with if you don't want to handle the folder-file structure
with relative import
And by doing so, vim YouCompleteMe
could be able to work correctly
By the way, in case you don't know: use `go get ./...` to install all missing packages for a Go project.