[Study notes] Golang start of HelloWord

golang installation

Enter the official website -> https://golang.org/

Choose their own system download

image-20200302220940596

Environment Variables

  • Adding Environment Variables

Mac to as terminal zsh example, the following command input

>> vi ~/.zshrc

In the last append the following codes

# /Users/quaint/study/golang-study 为你的golang 工作空间, 该空间下应该包含3个文件夹 src pkg bin
# root 为go安装目录 path 为go工作空间
export GOROOT=/usr/local/go
export GOPATH=/Users/quaint/study/golang-study
export PATH=$PATH:$GOROOT
export PATH=$PATH:$GOPATH:$GOPATH/bin
  • Check the Environment Variables

Restart terminal, enter the following command

>> go version
go version go1.14 darwin/amd64
>> go evn

查看 GOPATH 和 GOROOT 是否指向你的工作空间

vscode plug-in installation

  • chinese Chinese Simplified (Microsoft)

  • go (Microsoft)

go tools AnSo

Press the Mac platform Command+Shift+P, this time VS Code interface will pop up an input box, enter the following command.

Go:Install/Update Tools

Select All, click OK or press Enter

go.toolsGopath setting is not set. Using GOPATH /Users/quaint/study/golang-study
Installing 17 tools at /Users/quaint/study/golang-study/bin in module mode.
  gocode
  gopkgs
  go-outline
  go-symbols
  guru
  gorename
  gotests
  gomodifytags
  impl
  fillstruct
  goplay
  godoctor
  dlv
  gocode-gomod
  godef
  goreturns
  golint

Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs FAILED
Installing github.com/mdempsky/gocode FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs FAILED
Installing github.com/acroca/go-symbols FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing golang.org/x/tools/cmd/guru FAILED
Installing github.com/acroca/go-symbols FAILED
Installing golang.org/x/tools/cmd/gorename FAILED
Installing golang.org/x/tools/cmd/guru FAILED

You will find that many have failed to install. You can use git tools for installation.

The first step: now own GOPATHthe srccreated directory golang.org/xdirectory

Step Two: In 终端中cd under GOPATH / src / golang.org / x` directory

The third step: execute git clone https://github.com/golang/tools.git toolscommand

Step Four: Execute git clone https://github.com/golang/lint.gitcommand

Step Five: Press Ctrl/Command+Shift+Pexecuted again Go:Install/Update Toolscommand, in the pop-up window and click OK whole election, this time the installation will be SUCCESSEDup.

Write helloword

package main

import "fmt"

func main(){
    fmt.Println("hello world!");
}

Compile helloword

# 编译当前工作目录的go文件
>> go build
>> go build fileName
>> go build -o outName.exe

# 成功之后项目会多一个hello word 文件,执行他
>> ./helloword 
hello word!

Acknowledgments

Thanks Levin week's blog detailed the Go language tutorial.

Guess you like

Origin www.cnblogs.com/quaint/p/12405338.html