0

how can i do to import a package?

myproject

&nbsp&nbspmain.go

&nbsp&nbspRepository

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp DBHelper.go

&nbsp&nbspConfiguration

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Configuration.go

I need to call a function inside DBHelper.go from Configuration.go, how can i do it?

I need to call Select function from Configuration.go Thanks! Regards!

I Call Select but not working(undefined: DBHelper.Select in DBHelper)

  • import paths are defined by their directory relative to `$GOPATH/src/`. Please read ["How to Write Go Code"](https://golang.org/doc/code.html). It will explain how packages work in full. – JimB Jul 20 '16 at 18:12

1 Answers1

2

Package imports are relative from your GOPATH

For example, if DBHelper.go uses package "helpers", your import would look like this:

<name of project folder>/Repository/helpers

Here is a very similar question on the subject: How to use custom packages in Go

--Edit

Almost forgot, to perform the actual function call, you must use the package name / alias.

helpers.MyFunc()
Community
  • 1
  • 1
tier1
  • 6,303
  • 6
  • 44
  • 75
  • DBHelper.go not use helpers, i have something like this package Repository import (_"github.com/minus5/gofreetds" "../Configuration" "database/sql" "fmt" ) func Select(){} – Joaquin Noé Jul 20 '16 at 18:03
  • @JoaquinNoé I just used package name "helpers" as an example. Replace it with whatever your package name actually is. – tier1 Jul 20 '16 at 18:06
  • I not use /Repository/helpers instead of i use ../Repository – Joaquin Noé Jul 20 '16 at 18:29