26

vscode golang 开发环境搭建

 4 years ago
source link: https://studygolang.com/articles/25263
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

因为不花钱的goland毕竟不是正途,所以耗点精力搭建基于vscode的开发环境是有必要的。

跟着本文,你可以得到

  1. docker开发环境
  2. vscode + ssh
  3. 远程golang语言服务器

docker

  • 注意事项: 默认docker不支持fork,所以vscode F5 debug会报错。

添加 --security-opt=seccomp:unconfined 参数来允许容器执行全部的系统的调用可以解决这个问题

docker run --security-opt=seccomp:unconfined --name wmw-ubuntu-18.04 -p 20022:22 -it ubuntu /bin/bash

安装go

修改 .bashrc ,添加如下内容

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
# 强制开启module模式
export GO111MODULE=on
# 配置Proxy之后,就可以愉快的go get了
export GOPROXY=https://goproxy.io

export PATH=$GOPATH:$GOBIN:$GOROOT/bin:$PATH:$HOME/.local/bin
  • 注:开启 GO111MODULE 之后,则引用本地package时,不能再使用相对路径了。
uEVrUbV.png!web

import写法

vscode

安装插件

Local安装

Name: Remote - SSH

Id: ms-vscode-remote.remote-ssh

Description: Open any folder on a remote machine using SSH and take advantage of VS Code's full feature set.

Version: 0.47.2

Publisher: Microsoft

VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh

Name: Remote - SSH: Editing Configuration Files

Id: ms-vscode-remote.remote-ssh-edit

Description: Edit SSH configuration files

Version: 0.47.2

Publisher: Microsoft

VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh-edit

Remote安装

Name: Go

Id: ms-vscode.go

Description: Rich Go language support for Visual Studio Code

Version: 0.11.9

Publisher: Microsoft

VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go

zYrYVba.png!web

大功告成

Make things better

  • 编辑代码生成
feYRZ3Y.png!web

ctrl + shift + p

MB7fymf.png!web

添加代码生成片段


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK