I have own issue my whole project follow relative schema ./db

57 views
Skip to first unread message

Ali Hassan

unread,
Jul 25, 2020, 3:30:22 PM7/25/20
to golang-nuts
I have own issue my whole project follow relative schema (./db) , but I want like this .
                                     import ( github.com/username/projecr-name,package-name).
How ???

Brian Candler

unread,
Jul 26, 2020, 3:46:13 AM7/26/20
to golang-nuts
Use go modules.

In the top directory:

This creates go.mod in the top directory.

Put additional packages in their own subdirectories.  But *don't* run "go mod init" for these.  They all share the top one.

Example: foo/bar.go contains 
package xyz
func Doit() {
    ...
}

Your users can then import it like this:

xyz.Doit()

The packages in other subdirectories of your module can refer to each other in the same way.  They should *not* use relative imports.  Forget that relative imports ever existed, and it will all work.
Reply all
Reply to author
Forward
0 new messages