So I'm guessing that your dev tree looks something like this:
src
├───algo
├───database_sql
├───github.com
├───golang.org
├───GoogleAPI
├───googlemaps.github.io
├───main
├───main.go
├───models
├───myDebug
├───router
└───server
└───server.go
As you can see in How to Write Go Code, you are supposed to have a folder for your project, so main.go should be someproject/main.go
and you can then just use go build
to build the entire project.
Ideally you will want to have all your projects in a folder for their web address, like github.com/yourname/projectname
. I recommend you follow this convention even if a specific project is not going to be publicly accessible. I keep all my projects (even the ones that are not in github) in my github/my user
folder. This way it's easier to find and classify all you software.
If you want to build a project and all of it's dependencies (in this case server/server.go) you can do go build ./...
You can also go into the server package and do go install
to install build and reinstall the package.
So you should have something like this:
GOPATH
├───bin
| └───main (this will have the name of the folder)
├───pkg (this routes match the ones on src)
| └───linux_amd64
| └───server.a
└───src
├───algo
├───database_sql
├───github.com
├───golang.org
├───GoogleAPI
├───googlemaps.github.io
├───main
| └───main.go
├───models
├───myDebug
├───router
└───server
└───server.go
And then go to src/main/
and do go build ./...
to build all the dependencies. Ideally you will want to do go install ./...
so that libraries are installed on the correct path, and your binaries also get created in the correct path and not in the src
folder. If you do this, you will need to run the binary bin/main
. I recommend that you add GOPATH/bin
to your path so that you can install your software and just run it without going to the bin folder.
Probably there is some error in the way you are importing or using the server package. This is the best I can do without you posting your code.
Edit: After further thinking about this, I believe I found the error. You were doing go build
to build the whole project, and at some point you did go install
on the server library. So now go build
is using the already compiled version of the library in pkg
, so if you want to fix the problem do go install
on the server file or go install ./...
on the main folder.
This is not an error in Go, usually you don't want a change in a library to break your code, so you have to remember to install the new version of a library before trying your code.