Go開發問題集錦

windows下使用IDEA開發Linux系統syscall調用

  1. 首先是編譯sys庫

在命令行下輸入:set GOOS=linux,回車linux

而後執行:go get golang.org/x/sys/unix,回車git

就能夠看到編譯成功github

  1. 在IDEA使用系統調用

打開IDEA,點擊settingsgolang

在 「Languages & Frameworks」 > "Go" > "Vendoring & Build Tags" 中設置OS爲linuxwindows

applay以後,就能夠出現提示了app

使用mmap提示:permission denied

是因爲open一個文件,默認是read_only。而mmap的時候使用了write權限致使。ui

如:fin, error := os.Open(mmapFile)spa

而mmap是:mmap, err := unix.Mmap(int(fin.Fd()), 0, 100, unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED)插件

golang.org被牆解決

經過github.com下載源碼,而後編譯解決。這裏以VSCode安裝依賴爲例命令行

  1. 安裝github.com/josharian/impl 會依賴golang.org/x/tools。先下載x/tools,地址:https://github.com/golang/tools.git
$ pwd
/home/myname/workspace/golang/go_ext/src
$ git clone https://github.com/golang/tools.git  'golang.org/x/tools'
....下載x/tools....
$ git clone https://github.com/josharian/impl.git 'github.com/josharian/impl'
....下載impl....
$ go install github.com/josharian/impl
$ ls ../bin
....能夠看到impl安裝成功....

2.安裝dlv

$ git clone https://github.com/derekparker/delve.git 'github.com/derekparker/delve'
$ go install github.com/derekparker/delve/cmd/dlv

3.安裝go-outline

$ git clone https://github.com/ramya-rao-a/go-outline.git github.com/ramya-rao-a/go-outline
$ go install github.com/ramya-rao-a/go-outline

4.安裝godef

$ git clone https://github.com/rogpeppe/godef.git github.com/rogpeppe/godef
$ go install github.com/rogpeppe/godef

5.安裝go-symbols

$ git clone https://github.com/acroca/go-symbols.git github.com/acroca/go-symbols
$ go install github.com/acroca/go-symbols

6.安裝godoc goru gorename

$ go install golang.org/x/tools/cmd/godoc
$ go install golang.org/x/tools/cmd/gorn
$ go install golang.org/x/tools/cmd/gorename

7.安裝sourcegraph.com/sqs/goreturns

$ git clone https://github.com/sqs/goreturns.git github.com/sqs/goreturns
$ go install github.com/sqs/goreturns

8.安裝github.com/golang/lint/golint

$ git clone https://github.com/golang/lint.git github.com/golang/lint
$ go install github.com/golang/lint/golint

9.安裝github.com/cweill/gotests

$ git clone https://github.com/cweill/gotests.git github.com/cweill/gotests
$ go install github.com/cweill/gotests/...

注意install的時候是三個點

cannot resolve file問題

在intellij 2017.1使用go1.10時,出現此問題。後來查找說插件不支持1.10,就降級到go1.9.5 而後在file-->settings-->Languages & Frameworks-->Go-->GOROOT 選擇go的安裝位置。 而且發現不能像以前,在project structure-->Platform Settings-->sdks中設置gosdk了

相關文章
相關標籤/搜索