英文:
Go import file from another directory
问题
我正在尝试将utility
导入到github_events.go
中。
utility.go
文件位于services
目录下。
utility.go
的内容如下:
package utility
import (
"os"
"regexp"
)
我的项目结构如下:
这是从github_events.go
中导入的方式:
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"sync"
"time"
"sort"
"github-app/services/utility"
)
我还尝试使用别名utility "github-app/services/utility"
。
但是我得到了以下错误could not import github-app/services/utility (no required module provides package "github-app/services/utility")compilerBrokenImport
。
我的go.mod
文件内容如下:
module github-app
go 1.18
我做错了什么?
英文:
I'm trying to import utility
into github_events.go
.
utility.go
is placed under services
directory.
utility.go
looks like this:
package utility
import (
"os"
"regexp"
)
My project structure looks like this:
This is how import from github_events.go
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"sync"
"time"
"sort"
"github-app/services/utility"
)
I also tried with an alias utility "github-app/services/utility"
But I get the following error could not import github-app/services/utility (no required module provides package "github-app/services/utility")compilerBrokenImport
My go.mod
file:
module github-app
go 1.18
What am I doing wrong?
答案1
得分: 2
只需导入"github-app/services",你就可以开始了。
英文:
Just import "github-app/services" and you're good to go.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论