Use function in another Golang folder

1

I created a pacote within $GOPATH/src/github.com/meu-user/meupacote with a meupacote.go file that has the main function and another folder with the name products that has the products.go file, in this my products.go file a getBySKU function, how can I use this function in my main file meupacote.go ? see the example below:

- meupacote
  - products
    -products.go
  - meupacote.go

I am trying to use it directly because it is "inside the same package" and I only get the error that the getBySKU function is undefined, I also tried to define the function as "exportable" with GetBySKU and the same error remains .

    
asked by anonymous 18.01.2018 / 00:58

1 answer

1

Within the framework you put in, you can set products to be a package

products.go

package products
(...)

And in my meupacote.go you do import by usual way, but setting meupacote to be products root!

meupacote.go

(...)
import "github.com/meu-user/meupacote/products"

Remembering to define the GetBySKU function as exportable

    
18.01.2018 / 18:01