intellij-idea - Go 从命令行工作,但不是从 IntelliJ Idea Go

标签 intellij-idea go

在 Mac OS X 下,我执行了 brew install go。我还从这里下载了 Go IntelliJ IDE

http://go-ide.com/2011/08/09/goide_release_1_0_darwin.html

以下程序在命令行中编译和运行良好,但如果我使用 GO IntelliJ IDE,它会给出错误:

can't find import: math/rand

导入时间似乎没问题,但 Duration 和 time.Millisecond 未定义。如果我删除这些东西并只运行“Hello World 版本”,程序编译并运行良好。

/**
 * Created by IntelliJ IDEA.
 * User: idf
 * Date: 4/2/14
 * Time: 1:59 PM
 * To change this template use File | Settings | File Templates.
 */

package main

import (
  "fmt"
  "math/rand" /* causes problems */
  "time"
)

func main() {

    sleep := time.Duration(200) /* error: undefined: time.Duration */
    time.Sleep(sleep * time.Millisecond) /* error: undefined: time.Millisecond */


    rand.Intn(1000)

    fmt.Println("Hello World")
}

最佳答案

已更新:
你需要添加你的 GOROOT 和 GOPATH: https://github.com/go-lang-plugin-org/go-lang-idea-plugin/blob/master/Missing%20ENV.md

我运行的确切命令(显然,您的 GOPATH 和 GOROOT 会有所不同):

launchctl setenv GOPATH /Users/wfreeman/gocode
launchctl setenv GOROOT /Users/wfreeman/go1.2

关于intellij-idea - Go 从命令行工作,但不是从 IntelliJ Idea Go,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22821000/

相关文章:

google-app-engine - Google App Engine Golang 导入不起作用

c - 使用 golang 的 Windows Hook

go - 有没有办法从golang中的 map 中删除第一个元素?

jakarta-ee - 如何使用 Java EE IntelliJ IDEA 社区版

javascript - 在 IntelliJ IDEA 中更新 Jest 快照测试

intellij-idea - IntelliJ for Android xml 文件中的自动代码格式化

python - 在 virtualenv 中使用解释器时,IntelliJ IDEA 14 无法识别 Python 内置类型

go - 如何通过匹配的字符串变量在结构中选择键 ID

amazon-web-services - 在 golang 中订阅 SNS 主题和/或 SQS 队列?

java - Intellij IDEA 编辑器 : classpath order