2016-07-20 43 views
-1

我該如何導入一個包?如何在Go中導入本地包?

的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

我需要從Configuration.go中調用DBHelper.go中的函數,我該怎麼做?

I need to call Select function from Configuration.go 謝謝!問候!

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

+0

導入路徑由它們相對於'$ GOPATH/src /'的目錄定義。請閱讀[「如何編寫Go代碼」](https://golang.org/doc/code.html)。它將解釋軟件包是如何工作的。 – JimB

回答

1

包裝進口從GOPATH相對

例如,如果DBHelper.go使用包「幫手」,你將進口看起來像這樣:

<name of project folder>/Repository/helpers 

這裏是一個非常類似的問題: How to use custom packages in Go

- 編輯

差點忘了,要執行實際的函數調用,必須使用包名/別名。

helpers.MyFunc() 
+0

DBHelper.go不能使用助手,我有這樣的事包庫 進口(_ 「github.com/minus5/gofreetds」 \t 「../Configuration」 \t 「數據庫/ SQL」 \t 「FMT」 ) func Select(){} –

+0

@JoaquinNoé我剛剛用包名「helpers」爲例。用你的軟件包名稱實際上替換它。 – tier1

+0

我不使用<項目文件夾的名稱>/Repository/helpers而不是我使用../ Repository –