0

I developed one go service and deployed it on GAE. At the time of developing this application, I included required go modules using command in my work machine-

go get -u <module-name> 

I am able to include other required go modules using following commands -

adtech-adlib-web> go mod init

It created one go.mod file with message-

go: creating new go.mod: module github.com/nytm/adtech-adlib-web

than, I executed below command to download required modules in vendor folder as-

adtech-adlib-web> go mod vendor

Now, I want to commit this go code in my feature branch where code automatically deploys through .drone.io tool in repository. However, my build gets failed with only error :

cannot find package "backend" in any of:
/drone/src/github.com/nytm/adtech-adlib-web/vendor/backend (vendor tree)
/usr/local/go/src/backend (from $GOROOT)
/drone/src/backend (from $GOPATH) 

In my .drone.yml file section which creates problem is -

  backend-test:
image: jprobinson/golang-gcloud-sdk:1.11
environment:
  - GOPATH=/drone
  - PATH=/bin:/usr/bin:/usr/local/go/bin:/usr/local/go_appengine
commands:
  - go test -v ./backend/...
when:
  event: [push, pull_request]

I don't know how to resolve this problem? If go mod vendor can help in this case, how to use it and at which folder level I would have to execute this? Please explain all steps to perform.

Aniruddha Dwivedi
  • 91
  • 1
  • 2
  • 13
  • Have you read and understood https://github.com/golang/go/wiki/Modules? – Markus W Mahlberg Jul 18 '19 at 11:15
  • @MarkusWMahlberg hey Marks, I read article of link provided by you & now only thing breaking the build is root folder of my golang code which is in parallel with UI code, .drone.yml file and other things. This folder is not recognised by this service. I guess this particular thing will not be fixed by go mod init and vendor as this is my own folder. – Aniruddha Dwivedi Jul 18 '19 at 13:41
  • running `go build` inside any valid package path should build your application regardless of what else is in there. – Markus W Mahlberg Jul 18 '19 at 15:32

2 Answers2

0

From this error message, it looks like you're building in GOPATH mode (with modules disabled).

cannot find package "backend" in any of:
/drone/src/github.com/nytm/adtech-adlib-web/vendor/backend (vendor tree)
/usr/local/go/src/backend (from $GOROOT)
/drone/src/backend (from $GOPATH)  <--- building in GOPATH mode

Try setting GO111MODULE=on in your environment. Since you're using a vendor directory, you may also want to set -mod=vendor to ensure that packages are loaded from the vendor directory instead of the module cache (and the network).

When GO111MODULE is not set or set to auto, module-aware mode is only enabled when you start the build outside GOPATH. This will change in go1.13: modules will also be enabled if there's a go.mod file in any parent directory.

Jay Conrod
  • 28,943
  • 19
  • 98
  • 110
0

I forgot to mention full github path of my golang service folder in main.go as-

import ( ....

backend "github.com/org_name/repo_name/backend"

......... )

Aniruddha Dwivedi
  • 91
  • 1
  • 2
  • 13