Is ok to import multiple times?

Is it ok to import the same folder several times? I do it like this becouse the files of my routes are in that folder and I add the identifier to know what route it is and then call the function.

inside my routes folder i have

routes_
       |_ route_1.go
       |_ route_2.go
       |_ route_3.go

Import example

import(
    Route1 "./routes"
    Route2 "./routes"
    Route3 "./routes"
)

func main(){
    Route1.get()
    Route2.post()
    Route3.put()
}

All files in the same folder belong to the same package, so all 3 imports are the same anyway, therefore it is not necessary to to do 3 imports.

1 Like

What about importing from a different folder?

I’m using wasm, and in Svelte want to access the same Go package from components that may be in different subfolders of the root where the Go/wasm is imported.

I’m not even sure this is a Go question!

1 Like

The “same” go package can not be in different folders.

All files in a folder belong to the same package, different folders are different packages.

1 Like

Imports should really have a full path

eg “github.com/gorilla/mux

Relative paths should not be used as they don’t work very well.

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