how to run golang project downloaded from github - go

i have downloaded a project from github for some testing. the code is in go language. when i edited the code and run , many errors occoured.
I have tried to run project using D:\go>go run demo command.
how should i run the project?
here are the errors:
D:\go>go run hardentools-master
bin\src\hardentools-master\powershell.go:20:2: cannot find package "errors" in any of:
D:\go\bin\src\errors (from $GOROOT)
C:\Users\admin\go\src\errors (from $GOPATH)
bin\src\hardentools-master\gui.go:20:2: cannot find package "flag" in any of:
D:\go\bin\src\flag (from $GOROOT)
C:\Users\admin\go\src\flag (from $GOPATH)
bin\src\hardentools-master\adobe.go:20:2: cannot find package "fmt" in any of:
D:\go\bin\src\fmt (from $GOROOT)
C:\Users\admin\go\src\fmt (from $GOPATH)
bin\src\hardentools-master\gui.go:26:2: cannot find package "github.com/lxn/walk" in any of:
D:\go\bin\src\github.com\lxn\walk (from $GOROOT)
C:\Users\admin\go\src\github.com\lxn\walk (from $GOPATH)
bin\src\hardentools-master\gui.go:27:2: cannot find package "github.com/lxn/walk/declarative" in any of:
D:\go\bin\src\github.com\lxn\walk\declarative (from $GOROOT)
C:\Users\admin\go\src\github.com\lxn\walk\declarative (from $GOPATH)
bin\src\hardentools-master\adobe.go:22:2: cannot find package "golang.org/x/sys/windows/registry" in any of:
D:\go\bin\src\golang.org\x\sys\windows\registry (from $GOROOT)
C:\Users\admin\go\src\golang.org\x\sys\windows\registry (from $GOPATH)
bin\src\hardentools-master\main.go:73:2: cannot find package "io" in any of:
D:\go\bin\src\io (from $GOROOT)
C:\Users\admin\go\src\io (from $GOPATH)
bin\src\hardentools-master\gui.go:22:2: cannot find package "io/ioutil" in any of:
D:\go\bin\src\io\ioutil (from $GOROOT)
C:\Users\admin\go\src\io\ioutil (from $GOPATH)
bin\src\hardentools-master\main.go:74:2: cannot find package "log" in any of:
D:\go\bin\src\log (from $GOROOT)
C:\Users\admin\go\src\log (from $GOPATH)
bin\src\hardentools-master\gui.go:23:2: cannot find package "os" in any of:
D:\go\bin\src\os (from $GOROOT)
C:\Users\admin\go\src\os (from $GOPATH)

You can check the release page, you have an executable ready to use : https://github.com/securitywithoutborders/hardentools/releases

Related

How to compile gomuks on Ubuntu?

Trying to compile gomuks, following its insallation instructions, I get this error:
$ go install
gomuks.go:25:2: cannot find package "maunium.net/go/gomuks/config" in any of:
/usr/lib/go-1.10/src/maunium.net/go/gomuks/config (from $GOROOT)
/home/ettinger/go/src/maunium.net/go/gomuks/config (from $GOPATH)
gomuks.go:26:2: cannot find package "maunium.net/go/gomuks/debug" in any of:
/usr/lib/go-1.10/src/maunium.net/go/gomuks/debug (from $GOROOT)
/home/ettinger/go/src/maunium.net/go/gomuks/debug (from $GOPATH)
gomuks.go:27:2: cannot find package "maunium.net/go/gomuks/interface" in any of:
/usr/lib/go-1.10/src/maunium.net/go/gomuks/interface (from $GOROOT)
/home/ettinger/go/src/maunium.net/go/gomuks/interface (from $GOPATH)
gomuks.go:28:2: cannot find package "maunium.net/go/gomuks/matrix" in any of:
/usr/lib/go-1.10/src/maunium.net/go/gomuks/matrix (from $GOROOT)
/home/ettinger/go/src/maunium.net/go/gomuks/matrix (from $GOPATH)
main.go:30:2: cannot find package "maunium.net/go/gomuks/ui" in any of:
/usr/lib/go-1.10/src/maunium.net/go/gomuks/ui (from $GOROOT)
/home/ettinger/go/src/maunium.net/go/gomuks/ui (from $GOPATH)
What is the reason, how to solve it?
This repo uses Go modules feature and installation instructions clearly state it requires Go 1.13 or higher:
Install Go 1.13 or higher
From error messages it seems you have Go 1.10 which doesn't support modules (and likely also other features this repo depends on).
This error is caused by fact that prior modules support was added to Go in version 1.11; go tool was always looking up modules in $GOROOT and $GOPATH locations - and in your case it can't find them there.
Install Go 1.13 or higher to make the installation guide work. You can find recent enough packages in backport PPA or install latest from official tarball available here.

can't find attrmgr (from $GOROOT) and $GOPATH?

I am trying to install chaincode. I used cid package inside my chaincode When I try to install chaincode, I got the following error:
cannot load package:
package github.com/hyperledger/fabric/core/chaincode/lib/cid: cannot find package "github.com/hyperledger/fabric/core/chaincode/lib/cid" in any of:
/opt/go/src/github.com/hyperledger/fabric/core/chaincode/lib/cid (from $GOROOT)
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/lib/cid (from $GOPATH)
I have used glide tool( here https://github.com/Masterminds/glide) to fix it,
now i see another error that I couldn't fix which is:
Error: could not assemble transaction, err proposal response was not successful, error code 500, msg error starting container: error starting container: Failed to generate platform-specific docker build: Error returned from build: 1 "chaincode/input/src/github.com/chaincode/vendor/github.com/hyperledger/fabric/core/chaincode/lib/cid/cid.go:29:2: cannot find package "github.com/hyperledger/fabric/common/attrmgr" in any of:
/chaincode/input/src/github.com/chaincode/vendor/github.com/hyperledger/fabric/vendor/github.com/hyperledger/fabric/common/attrmgr (vendor tree)
/chaincode/input/src/github.com/chaincode/vendor/github.com/hyperledger/fabric/common/attrmgr
/opt/go/src/github.com/hyperledger/fabric/common/attrmgr (from $GOROOT)
/chaincode/input/src/github.com/hyperledger/fabric/common/attrmgr (from $GOPATH)
/opt/gopath/src/github.com/hyperledger/fabric/common/attrmgr
Any suggestion؟
Install the fabric dependency in your GOPATH, go get -u github.com/hyperledger/fabric

go race detector can't run because of import error. ports runtime/race: cannot find package "runtime/race" in any of GOROOT or GOPATH

my os is ubuntu18.04.
my go compiler is gccgo.
GOROOT is /usr/local/go
it is report as:
package testmain
imports runtime/race: cannot find package "runtime/race" in any of:
/usr/local/go/src/runtime/race (from $GOROOT)
/home/lzx/tiny_distributed_system/src/runtime/race (from $GOPATH)

cannot find vendor package in windows

I have my GOPATH and GOROOT set, currently trying to use a package located in the vendor folder, while doing go run in my windows I get
C:\resume>go run docs/generator.go
docs\generator.go:13:2: cannot find package "github.com/tidwall/gjson" in any
of:
C:\Go\src\github.com\tidwall\gjson (from $GOROOT)
C:\resume\src\github.com\tidwall\gjson (from $GOPATH)
My GOROOT=C:\Go, GOPATH=C:\resume and PATH=C:\Go\bin

How to import a golang own package?

I have problems with importing a package. I want to import the "golang.org/x/tools/cmd/oracle" and the "golang.org/x/tools/oracle" package.
Which is the correct way to import these packages?
This the way I try to import the packages:
package main
import (
"fmt"
"strings"
"os"
"os/exec"
"golang.org/x/tools/oracle"
"golang.org/x/tools/cmd/oracle"
)
The both last imports leads to the following problem:
==================== Starting Go build ====================
Cleared problem markers for ProjektGO.
************ Building Go project: ProjektGO ************
with GOPATH: /home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO
>> Running: /usr/lib/go/bin/go install -v -gcflags "-N -l" ./...
file/main.go:13:2: cannot find package "golang.org/x/tools/cmd/oracle" in any of:
/usr/lib/go/src/golang.org/x/tools/cmd/oracle (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/cmd/oracle (from $GOPATH)
file/main.go:12:2: cannot find package "golang.org/x/tools/oracle" in any of:
/usr/lib/go/src/golang.org/x/tools/oracle (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/oracle (from $GOPATH)
^^^ Terminated, exit code: 1 ^^^
************ Build terminated. ************
Then I tried things like that:
package main
import (
"fmt"
"strings"
"os"
"os/exec"
"../../../../../golang.org/x/tools/cmd/oracle"
"../../../../../golang.org/x/tools/oracle"
)
And the result was this:
==================== Starting Go build ====================
************ Building Go project: ProjektGO ************
with GOPATH: /home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO
>> Running: /usr/lib/go/bin/go install -v -gcflags "-N -l" ./...
can't load package: /home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/file/main.go:11:2: import "../../../../../golang.org/x/tools/cmd/oracle" is a program, not an importable package
../../../../golang.org/x/tools/oracle/describe.go:20:2: cannot find package "golang.org/x/tools/go/ast/astutil" in any of:
/usr/lib/go/src/golang.org/x/tools/go/ast/astutil (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/ast/astutil (from $GOPATH)
../../../../golang.org/x/tools/cmd/oracle/main.go:26:2: cannot find package "golang.org/x/tools/go/buildutil" in any of:
/usr/lib/go/src/golang.org/x/tools/go/buildutil (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/buildutil (from $GOPATH)
../../../../golang.org/x/tools/oracle/callers.go:11:2: cannot find package "golang.org/x/tools/go/callgraph" in any of:
/usr/lib/go/src/golang.org/x/tools/go/callgraph (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/callgraph (from $GOPATH)
../../../../golang.org/x/tools/cmd/oracle/main.go:27:2: cannot find package "golang.org/x/tools/go/loader" in any of:
/usr/lib/go/src/golang.org/x/tools/go/loader (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/loader (from $GOPATH)
../../../../golang.org/x/tools/oracle/callees.go:17:2: cannot find package "golang.org/x/tools/go/pointer" in any of:
/usr/lib/go/src/golang.org/x/tools/go/pointer (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/pointer (from $GOPATH)
../../../../golang.org/x/tools/oracle/callees.go:18:2: cannot find package "golang.org/x/tools/go/ssa" in any of:
/usr/lib/go/src/golang.org/x/tools/go/ssa (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/ssa (from $GOPATH)
../../../../golang.org/x/tools/oracle/callees.go:19:2: cannot find package "golang.org/x/tools/go/ssa/ssautil" in any of:
/usr/lib/go/src/golang.org/x/tools/go/ssa/ssautil (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/ssa/ssautil (from $GOPATH)
../../../../golang.org/x/tools/oracle/describe.go:22:2: cannot find package "golang.org/x/tools/go/types/typeutil" in any of:
/usr/lib/go/src/golang.org/x/tools/go/types/typeutil (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/types/typeutil (from $GOPATH)
../../../../golang.org/x/tools/cmd/oracle/main.go:28:2: cannot find package "golang.org/x/tools/oracle" in any of:
/usr/lib/go/src/golang.org/x/tools/oracle (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/oracle (from $GOPATH)
../../../../golang.org/x/tools/oracle/callees.go:20:2: cannot find package "golang.org/x/tools/oracle/serial" in any of:
/usr/lib/go/src/golang.org/x/tools/oracle/serial (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/oracle/serial (from $GOPATH)
../../../../golang.org/x/tools/oracle/implements.go:21:2: cannot find package "golang.org/x/tools/refactor/importgraph" in any of:
/usr/lib/go/src/golang.org/x/tools/refactor/importgraph (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/refactor/importgraph (from $GOPATH)
^^^ Terminated, exit code: 1 ^^^
************ Build terminated. ************
My GOROOT is /usr/lib/go and my GOPATH is /home/haapoo/go .
I know the question about gopath and goroot comes often but maybe anyone has an idea.
PS: I use goclipse
Greetings
haapoo
Have you run go get golang.org/x/tools/oracle and go get golang.org/x/tools/cmd/oracle ? This should be run after $GOPATH is properly set.
Never ever set GOROOT. (Unless you know what you are doing). Setting it is not needed.
As you cannot import golang.org/x/tools/cmd/oracle as this is a main package. At least you cannot do this the easy way and you should not anyway (except if you want to test the imported main package).
Importing is not magic, you'll have to download the package before using it. Use go get as others have mentioned.
Build on the command line to be sure what you are doing and how you are doing it (IDEs tend to blur things here).
If you need to import different packages of the same name in Golang, this is the way(just name it):
import (
"text/template"
ht "html/template"
)
but in case of "golang.org/x/tools/cmd/oracle"
it is not a package , it has just main.go and you need to build/install it. it is a command line tool:
Run 'oracle -help' for more information.
Go source code oracle.
Usage: oracle [<flag> ...] <mode> <args> ...
The -format flag controls the output format:
plain an editor-friendly format in which every line of output
is of the form "pos: text", where pos is "-" if unknown.
json structured data in JSON syntax.
xml structured data in XML syntax.
oracle is a source analysis command line tool, you can't import it. Use the following command to get it:
go get golang.org/x/tools/cmd/oracle
This will create an executable named oracle in your $GOPATH/bin directory.
Visit http://golang.org/s/oracle-user-manual for the complete oracle documentation.

Resources