-1

Build (Fails):

GO111MODULE=off go build -o diameter
[pceuser@pincb-brm02 src]$ echo $GOPATH 

/home/pceuser/policy-control-engine

[pceuser@pincb-brm02 src]$ pwd

/home/pceuser/policy-control-engine/src

[pceuser@pincb-brm02 src]$ ls

backupgx config.go data.csv go.mod gx.go model.go README redis_test.go stats.go ccr.go config.yml diameter go.sum Makefile pcediam redis.go server.go vendor

[pceuser@pincb-brm02 src]$ cd vendor
[pceuser@pincb-brm02 vendor]$ ls

github.com golang.org gopkg.in modules.txt

Error on build:

ccr.go:8:2: cannot find package
"github.com/fiorix/go-diameter/v4/diam" in any of:
    /usr/local/go/src/github.com/fiorix/go-diameter/v4/diam (from
$GOROOT)
    /home/pceuser/policy-control-engine/src/github.com/fiorix/go-diameter/v4/diam
(from $GOPATH)

ccr.go:9:2: cannot find package
"github.com/fiorix/go-diameter/v4/diam/avp" in any of:
    /usr/local/go/src/github.com/fiorix/go-diameter/v4/diam/avp (from
$GOROOT)
    /home/pceuser/policy-control-engine/src/github.com/fiorix/go-diameter/v4/diam/avp
(from $GOPATH)

gx.go:11:2: cannot find package
"github.com/fiorix/go-diameter/v4/diam/datatype" in any of:
    /usr/local/go/src/github.com/fiorix/go-diameter/v4/diam/datatype
(from $GOROOT)
    /home/pceuser/policy-control-engine/src/github.com/fiorix/go-diameter/v4/diam/datatype
(from $GOPATH)

ccr.go:6:2: cannot find package
"github.com/fiorix/go-diameter/v4/diam/sm" in any of:
    /usr/local/go/src/github.com/fiorix/go-diameter/v4/diam/sm (from
$GOROOT)
    /home/pceuser/policy-control-engine/src/github.com/fiorix/go-diameter/v4/diam/sm
(from $GOPATH)

redis.go:6:2: cannot find package "github.com/go-redis/redis" in any
of:     /usr/local/go/src/github.com/go-redis/redis (from $GOROOT)
    /home/pceuser/policy-control-engine/src/github.com/go-redis/redis
(from $GOPATH)

config.go:6:9: cannot find package "gopkg.in/yaml.v2" in any of:
    /usr/local/go/src/gopkg.in/yaml.v2 (from $GOROOT)
    /home/pceuser/policy-control-engine/src/gopkg.in/yaml.v2 (from
$GOPATH)

Note: I made some changes in https://github.com/fiorix/go-diameter in my vendor dependency folder but still, I am unable to compile it.

shmsr
  • 3,802
  • 2
  • 18
  • 29
  • Have you tried `go build -mod=vendor`? This will load your dependencies from `vendor` package instead of finding them in global GOPATH – Oleksii Miroshnyk Apr 04 '20 at 14:13
  • There are tricks you can try and that might even work, but to know really the exact reason on why it's happening, I need some additional info. Can you once check if the said packages exist in the vendor directory. Also, share the output of `go env` and `go version`. – shmsr Apr 04 '20 at 14:34

1 Answers1

0

If you are outside GOPATH and do not use go modules and still trying to compile your project by using vendor folder, it is worth to try:

go build -mod=vendor

This prevents finding dependencies in the global GOPATH and will load your dependencies directly from vendor folder.