-4

My project depends on some private Go projects that are not go-gettable. Previously I just put then in the GOPATH at proper places (e.g., $GOPATH/src/mycompany/mylib/lib.go), and life was good. I.e., I don't need to apply any fancy techy hacks in,

Go modules, private repos and gopath

and I am able to get my job done.

Now, with go beyond 1.13, is there still any low tech solution, as simple as putting it at proper place under GOPATH to such problem?

Thanks

xpt
  • 20,363
  • 37
  • 127
  • 216

1 Answers1

1

If you want to go with the $GOPATH way, then this is still working on go1.14.1:

You can put both projects (not using gomodules) inside your GOPATH:

  1. Project foo is under GOPATH/src/foo/
  2. Project, our lib, greeting is under GOPATH/src/myfancycompany/greeting/

Our goal is that foo will import greeting.

Then foo/main.go will look like this:

package main

import "myfancycompany/greeting"

func main() {
    println("How to greet?")

    greeting.English()
}

And our lib myfancycompany/greeting/greeter.go will look like this:

package greeting

func English() {
    println("hi, i am boo")
}

Then go build main.go and run it ./main:

~/go/src/foo$ ./main
How to greet?
hi, i am boo
fabem
  • 156
  • 6
  • Thanks a lot fabem, that's the exact low-tech method that I'm looking for! and thanks for the working example too. Now I just need to go about and figure out why my setting is not working, but that should be minor issues. Thanks again!!! – xpt Apr 09 '20 at 21:53