dongpu2476 2019-03-31 07:54
浏览 784
已采纳

无法在vscode中运行第一个golang项目

I am new in golang.

i can not start my go file in VSCODE ,my code is simple

package main

import "fmt"

func main() {
    fmt.Println("test")
}

when i run go run main.go in my terminal every thing works fine but when i save it in my vscode i get too many errors all like

/work/src/golang.org/x/net/webdav/prop_test.go:217: encoding/xml.Name composite literal uses unkeyed fields

my main.go file located at /work

how can i solve the problem ?

  • 写回答

1条回答 默认 最新

  • douhuo3696 2019-03-31 11:40
    关注

    It looks to me like you've installed/unarchived Go at /work, which I assume is your home directory.

    As a result, when you try and build your program which is also in /work (rather than use go run from the command line), all of the code underneath the /work directory where your main.go file are also being checked by VS Code.

    The simplest solution might be to put your main.go file outside the work directory completely, or put it within the Go path at /work/src/github.com/<your_username>/<your_package>.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效