Importing local package

167 views
Skip to first unread message

D Whelp

unread,
Oct 9, 2018, 12:49:20 PM10/9/18
to golang-nuts
Hello all,

Super new to Golang, loving the hell out of it, but I am running into a small issue.  I have a small application that I am working through.  I can import my models using `import ("/dojo/pkg/models")` in main.go just fine.  Now I am trying to build a `cli` package and I cannot import it.  Every time I do, I cannot use the function `QueryESXi()` that is in my esxi.go  Attached is my layout.  I have tried "./cmd/cli" and "dojo/cmd/cli"... but none are working. What am I missing?  Thanks in advance.


Screen Shot 2018-10-09 at 10.45.24 AM.png

Constantin Konstantinidis

unread,
Oct 9, 2018, 2:21:38 PM10/9/18
to golang-nuts
I don't see clearly which OS you run on, but "../cli" should work if you run locally.

Justin Israel

unread,
Oct 9, 2018, 2:23:22 PM10/9/18
to D Whelp, golang-nuts


On Wed, Oct 10, 2018, 5:49 AM D Whelp <dal.wh...@gmail.com> wrote:
Hello all,

Super new to Golang, loving the hell out of it, but I am running into a small issue.  I have a small application that I am working through.  I can import my models using `import ("/dojo/pkg/models")` in main.go just fine.  Now I am trying to build a `cli` package and I cannot import it.  Every time I do, I cannot use the function `QueryESXi()` that is in my esxi.go  Attached is my layout.  I have tried "./cmd/cli" and "dojo/cmd/cli"... but none are working. What am I missing?  Thanks in advance.

There is a bit of missing info here. Assuming you are using a GOPATH like $GOPATH/src/dojo or you have a go.mod properly configured and are outside your GOPATH, then an import like "dojo/cmd/cli" could work. I would recommend sticking to absolute import paths and not using relative dot imports. What is the package name in your esxi.go file? The fact that it is in a cmd location implies that it would be a "main" package and thus not intended to be imported by another package. 



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

D Whelp

unread,
Oct 9, 2018, 6:20:47 PM10/9/18
to golang-nuts
Yes, my GOPATH and GOROOT are working fine in fact other local imports work as intended.  I made a idiotic mistake and wasted so much time googling when I shouldve seen what I was doing wrong.  I was calling `QueryESXi()` and adding the import line.  I left off the `cli.QueryESXi()`.  Once I did that importing `dojo/cmd/cli` worked like a champ.  Thank you so much for reaching out!
Message has been deleted

D Whelp

unread,
Oct 9, 2018, 7:06:55 PM10/9/18
to golang-nuts
Forgive my ignorance, I am working from MacOS but realized my mistake about 20 min after I had submitted the issue I was having.  The import wasnt really the issue, it was my usage of the QueryESXi function.  I was trying to call it directly but figured out after a few hours of frustration and googling that `cli.QueryESXi()` fixed my issue.  Super noob mistake on my part.  I apologize for wasting the communities time on something so trivial and appreciate the responses.  Thanks!
Reply all
Reply to author
Forward
0 new messages