V
V
Vanes Ri_Lax2019-05-11 17:16:12
go
Vanes Ri_Lax, 2019-05-11 17:16:12

Why is my package not being imported?

Good afternoon, I'm trying to figure out the golang language.
I have:
GOPATH=C:\Users\xxx\go
going to the given address, in the src folder I created the project
folder In the project I created the test1 folder and there I created the main.go file:

package main

func main() {
  Client1()
}

Next, in the test1 folder , I created 1 more folder and called it ld , in it I created the loader.go file:
package van

//test
func Client1() {
  println("test")
}

CT6yLKFFYhg.jpg
How can I correctly import this package in the main.go file so that the Client1 function becomes available?
P.S. I am using Visual Studio Code IDE

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nrgian, 2019-05-11
@nrgian

There are 2 main ways packages are located in Go:
Inside a directory specified in the GOPATH environment variable . This is where the src subdirectory should be. You put it there, for example, in src/mydir/mypackage.
Then everything in this src can be imported as import "mydir/mypackage"
The second way is with modules, but you don't use it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question