Golang packages error

Hello go bridgers, I have a problem with importing packages to golang workspace.
I am trying to import a package from within the same project directory but it’s not loading. Here’s the folder structure:

main.go (package main)
demo.go (package demo)

When I try to load load the demo package in main, it shows an error like:
[go] cannot find package "mypackage/demo" in any of: /usr/local/go/src/mypackage/demo (from $GOROOT) /home/me/work/src/mypackage/demo (from $GOPATH)

My import in main.go goes like this:
import (


Why am I getting this kind of error and how do I fix that
Ubuntu 18.04
Sorry for unformated text, I’m new here, Thank you.


You always need to specify full package path on import, including the guthub.com/username/repository ceremony…


I did so. I’m using vscode. After specifying the full path, when I save the file, the import statement disappears. I was wondering, must I run a go get on that package to be able to use it? (But I’m not committing the project to github yet)


Depending on how you configured vscode it will remove packages on save it thinks you do not use. This is a setting of the formatter IIRC… I consider this really annoying…

And you only need to go get if you haven’t the package available already.


Thank you, it works just fine. All I had to do was to use a different text editor (Brackets).


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.