I grabbed a Go project from GitHub for testing purposes and I’m having trouble getting it to work properly.
After making some changes to the source code, I tried executing it but ran into multiple import errors. I attempted using the command C:\golang>go run myproject but it’s not working as expected.
What’s the correct way to build and execute a Go application that I downloaded from a repository?
Here’s what I’m seeing when I try to run it:
C:\golang>go run securitytools-main
src\bin\securitytools-main\registry.go:15:2: cannot find package "fmt" in any of:
C:\golang\src\fmt (from $GOROOT)
C:\Users\user\go\src\fmt (from $GOPATH)
src\bin\securitytools-main\ui.go:18:2: cannot find package "os" in any of:
C:\golang\src\os (from $GOROOT)
C:\Users\user\go\src\os (from $GOPATH)
src\bin\securitytools-main\main.go:22:2: cannot find package "log" in any of:
C:\golang\src\log (from $GOROOT)
C:\Users\user\go\src\log (from $GOPATH)
src\bin\securitytools-main\ui.go:25:2: cannot find package "github.com/andlabs/ui" in any of:
C:\golang\src\github.com\andlabs\ui (from $GOROOT)
C:\Users\user\go\src\github.com\andlabs\ui (from $GOPATH)
It seems like Go can’t locate the standard library packages or external dependencies. What am I doing wrong here?
Your error shows you’re either running an old Go version or have a messed up GOPATH. When Go can’t find basic packages like fmt, os, and log, there’s something wrong with your installation setup. Go to your project directory where the go.mod file lives - modern Go uses modules, not the old GOPATH system. Run go mod tidy to grab all the dependencies from your module file. This’ll fix external packages like github.com/andlabs/ui. To run your project, use go run . for the main package or go build . then run the executable. Sounds like you’re mixing old GOPATH commands with newer module-based projects.
wrong command syntax. don’t use go run myproject - you need actual .go files or go run . from the project folder. got a go.mod file? cd into that directory first, then run your commands.
This looks like a Go installation problem, not something wrong with your project. When Go can’t find basic packages like fmt, os, and log, your GOROOT is probably pointing to the wrong place. Check that GOROOT points to your actual Go installation - usually C:\Go on Windows. Run go env GOROOT to see what it’s set to, then make sure that folder has a src directory with the standard library code. Also, make sure you’re running commands from the project’s root directory where the go.mod file or main Go files are located. If it’s a module-based project, go get will grab dependencies automatically when you build or run.
sounds like your go setup is messed up. those packages are default with go. try running go version to see if it’s installed right. also, be sure you’re in the same dir as main.go when you run the commands.
This error means you haven’t initialized Go modules yet. Go to your project directory and check if there’s a go.mod file. If it’s missing, run go mod init <module-name> to create one. Then run go mod download to grab all the dependencies, including external ones like github.com/andlabs/ui. Also check your GOROOT environment variable - it might be pointing to the wrong Go installation directory. Once that’s sorted, use go run main.go instead of trying to run the whole directory. I’ve hit this same issue before when cloning projects that weren’t set up for Go modules.