How to import a local package in a parent subdirectory

Hi, I’m having an issue with the Go packages, and maybe someone here can clarify the issue.

I have the project structured like this

image
Also the main.go file it is at the level of the “content” folder.

How can I import the acnhapi.go package called “package acnhapi.go” into bugs.go file? I’ve tried almost everything I could and I cannot find how.

Thanks in advance

2 Likes

So importing Go packages can be viewed something like this:

Your go.mod

module myawesomemodule

now each import of your module can be prefixed by this module name
according to your structure

main.go

package main

import "myawesomemodule/content/bugs"

func main() {
    bugs.SomeFunc()
}

bugs.go

package bugs

import "myawsomemodule/api"

func SomeFunc() {
    api.CallAPI()
}

and so on …

if you are not using go modules yet then it is time to do so by doing go mod init ${your_module_name}. It makes your life a lot easier.

5 Likes

Awesome, worked perfectly, thanks for the suggestion!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.