当前位置:网站首页>VsCode-Go

VsCode-Go

2022-04-23 16:54:00 The interview was rejected 10000 times

Use Vscode debugging go

  Install well [Vscode](https://code.visualstudio.com/)
  Install well [Go](https://go.dev/dl/)
 Windows  download .msi Package with suffix ,
 mac  download .pkg Package with suffix ,
 linux  Download suffix  tar.gz ( decompression  tar -zxvf  Package name )
 > go  Default installed in  C:\Program Files\GO  perhaps  C:\User\GO  Which one did I forget , I usually install it by default C"\ Under the root directory of 

Edit environment variables

Windows:

Individual user environment variables :

  GOPATH( Variable name ) :  C:\Go\bin ( A variable's value )
  Path( Variable name )   : C:\Go\bin ( A variable's value )

System variables :

 Path( Variable name )   : C:\Go\bin ( A variable's value )

linux

 vi  /etc/profile,
  write in  export PATH=$PATH:/usr/local/go/bin  sign out 
 source /etc/profile

Set up the environment , Access terminal Input go version , If the version is not displayed , Just restart the computer ....

Use Vscode To configure Go Environmental Science

Use Vscode Download a GO The expansion pack, , Open one Go Project folder for , Create a , Use VsCode Open this folder
Build test code

main.go

package main

import (
	"fmt"
)

func main() {
    
	fmt.Println("Hello World")
	fmt.Println("Hello World")
}

You will be prompted to install the plug-in , Due to some known problems , Downloading is a little troublesome , I just put my download into a package
Go Plug-in package , Unzip it and put it in the installation go The folder bin below

Set up go env

go env -w GO111MODULE=on //go The command line will use modules
go env -w GOPROXY=https://goproxy.cn,direct // Use seven cow cloud

Set up launch.json
New version of the Vscode You don't have to set it GOPATH and GOROOT, open Vscode function >> Add the configuration

{
    
"version": "0.2.0",
"configurations": [
    {
    
        "type": "go",
        "request": "launch",
        "name": "Launch",
        "mode":"debug",
        "program": "${file}"
    }
]
}

initialization mod

go mod init Project folder name

You can try debugging , Pay attention to main.go File startup F5 debugging , Be careful main.go The package name must be “package main”.

About go mod yes go1.11 Project management module , Learning this module can be accessed go mod Study

Configuration problem , Take a look at this blog Configuration learning

Configuration problem , Take a look at this blog Configuration learning

版权声明
本文为[The interview was rejected 10000 times]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231359046320.html