Some Notes About Go Imports and Modules

Some Notes About Go Imports and Modules

The following file organization was the one that made my project apparently work:

❯ tree
.
├── go.mod
├── go.sum
├── main.go
└── sftool
    └── sftool.go

1 directory, 4 files

The go.mod file makes sense to me now since it contains the “tablewriter” repo as a direct dependency and since this one is using “go-runewidth”, it has listed it as “indirect”.

❯ cat go.mod 
module github.com/rabocse/sfcli

go 1.18

require github.com/olekukonko/tablewriter v0.0.5

require github.com/mattn/go-runewidth v0.0.9 // indirect

In regards of the import section in the main.go file, here it is:

import (
        "net/http"

        "github.com/rabocse/sfcli/sftool"
)

Notice that the import path apparently must specify the dir itself where the code is located, otherwise I might get an error like this one:

❯ go build
package github.com/rabocse/sfcli
        imports github.com/rabocse/sfcli: import cycle not allowed

 Share!

 
comments powered by Disqus