# export 與 import

使用以下方法即可 import 另一個資料夾的 func，與go mod 不同的是 import時需要多寫上路徑。

1. 新增一個資料夾與一個要export的檔案

![](https://4289429853-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0u4DAQK8tk8n7ia5gg%2F-MBRRqZEmU7aGXSiNhWh%2F-MBRSZdBaksa5tLvRj4D%2F%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7%202020-07-05%20%E4%B8%8A%E5%8D%888.52.31.png?alt=media\&token=a9ed245d-e788-48a7-ad56-b9cad3c307d7)

```go
package concurrency

import (
	"fmt"
)

func Say(s string) {
	fmt.Print(s)
}
```

> 記得export 的 function 第一個字要大寫

2\.  新增 要 import的檔案

hello.go

```go
package main;

import (
	concurrency "./concurrency"
)

func main() {
	concurrency.Say("hello");
}
```

![](https://4289429853-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0u4DAQK8tk8n7ia5gg%2F-MBRRqZEmU7aGXSiNhWh%2F-MBRT-BP_RQ9KZ3KAFoD%2F%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7%202020-07-05%20%E4%B8%8A%E5%8D%888.54.44.png?alt=media\&token=d2bfc075-c246-4a5d-9690-18934838e78b)

之後即可。

## &#x20;使用 go mod 的話 import 只要放入 go mod 名稱在前面即可

```
go mod init test-backend
```

例如在 route 檔案可使用如下：

```
package routes

import (
	controllers "test-backend/controllers"
)

func CatchphrasesRoute(route fiber.Router) {
	route.Get("/", controllers.GetAllCatchphrases)
}
```
