-3

I have the following dir structure

~/test
 | lala
  - lala.go
 - main.go

And the contents:

main.go:

package main

import (
        "fmt"

        "./lala"
        _ "github.com/lib/pq"
)

func main() {
        fmt.Println(lala.asd)
}

lala.go:

package lala

import (
        _ "github.com/lib/pq"

        "github.com/gorilla/securecookie"
)

func asd() string {
        return string(securecookie.GenerateRandomKey(32))
}

Then i execute:

~/test$ go mod init asdasd.com/asdasd
~/test$ go mod tidy
~/test$ go run main.go

But i get

lala/lala.go:6:2: cannot find package

That line is the one with the securecookie, which is a remote path. I tried go mod init && go mod tidy in the lala dir but the error is the same.

1 Answers1

2

Do not make use of relative paths in imports. Your import path should start with the project directory(The directory under src folder).

Change this

import  "./lala"

To

import  "asdasd.com/asdasd/lala"
Ian Stapleton Cordasco
  • 26,944
  • 4
  • 67
  • 72
Ashwin Shirva
  • 1,331
  • 1
  • 12
  • 31
  • Im not using GOROOT to manage this _project_. Im actually trying to break from GOROOT to prevent me from having to put the full url path on imports. I thought modules would help, but apparently, those are just as broken as GOPATH. – Axel Bayerl Jun 07 '20 at 14:38
  • @AxelBayerl, GOROOT is never used to manage a project. “How to Write Go Code” walks you through what you want step by step. – JimB Jun 07 '20 at 14:52