gpt4 book ai didi

go - (来自 $GOROOT) ($GOPATH not set) in IntelliJ idea

转载 作者:IT王子 更新时间:2023-10-29 01:26:25 28 4
gpt4 key购买 nike

我已经开始在 IntelliJ Idea 中使用 golang。

我有以下代码

主要包

import (
"fmt"
"/github.com/zzz/stringutil"
)

func main() {
fmt.Printf(stringutil.Reverse("!oG ,olleH"))
}

我还有以下 stringutil.go 文件

// Package stringutil contains utility functions for working with strings.
package stringutil

// Reverse returns its argument string reversed rune-wise left to right.
func Reverse(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
return string(r)
}

我收到以下错误:

src\github.com\zzz\hello\hello.go:5:2: cannot find package "src/github.com/zzz/stringutil" in any of:
C:\Go\src\src\github.com\zzz\stringutil (from $GOROOT)
($GOPATH not set)

如何通过 Intellij 配置环境变量以便运行程序?

最佳答案

这是针对此问题的快速修复。我使用 inttelliJ idea 作为我的编辑器。我用的是MAC

  1. 转到首选项
  2. 在语言和框架下搜索 GO
  3. 如果您寻找 GOROOT,它应该像下面的屏幕截图一样

    enter image description here

  4. 如果您查找 GOPATH,设置应该类似于下面的屏幕截图

enter image description here

  1. 这是我的项目的完整路径。您可以将其自定义为按照你的需要。我的项目名称是adit /Users/mmdc/Documents/mataharimall-development/www/go/src/github.com/mataharimall/adit

关于go - (来自 $GOROOT) ($GOPATH not set) in IntelliJ idea,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41177788/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com