Table of Contents  目录

Prerequisites  前提条件

Install Go  安装Go

Write some code  编写一些代码

Write more code  编写更多代码

In this tutorial, you'll get a brief introduction to Go programming. Along the way, you will:

本教程中,你将对Go编程有简单的了解。沿着教程,你将:

go

Note: For other tutorials, see Tutorials.

注意:对于其它教程,请看教程。

Prerequisites  前提条件

  • Some programming experience. The code here is pretty simple, but it helps to know something about functions.  一些编程经验。这里的代码非常简单。但是具备函数的一些知识是有帮助的。
  • A tool to edit your code. Any text editor you have will work fine. Most text editors have good support for Go. The most popular are VSCode (free), GoLand (paid), and Vim (free).  一款编辑代码的工具。任何你可接受的文本编辑器。许多文本编辑器为Go提供了良好的支持。非常受欢迎的有VSCode(免费),GoLand(付费),和Vim(免费)。
  • A command terminal. Go works well using any terminal on Linux and Mac, and on PowerShell or cmd in Windows.  一个命令终端。使用Linux和Max上的任何终端和Windows上的PowerShell或cmd,Go都工作的很好。

Install Go  安装Go

Just use the Download and install steps.

只需参考下载和安装步骤。

Write some code  编写一些代码

Get started with Hello, World.

从Hello, World开始。

cd
cd %HOMEPATH%
mkdir hello
cd hello
$ go mod init example/hello
go: creating new go.mod: module example/hello
package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}
$ go run .
Hello, World!
$ go help

Call code in an external package  调用外部包的代码

When you need your code to do something that might have been implemented by someone else, you can look for a package that has functions you can use in your code.

当你需要你的代码做一些工作(这些工作可能已有其他人实现),你可以查找实现了功能(可以在你的代码中使用的功能)的包。

package main

import "fmt"

import "rsc.io/quote"

func main() {
    fmt.Println(quote.Go())
}
$ go mod tidy
go: finding module for package rsc.io/quote
go: found rsc.io/quote in rsc.io/quote v1.5.2
$ go run .
Don't communicate by sharing memory, share memory by communicating.

Write more code  编写更多代码

With this quick introduction, you got Go installed and learned some of the basics. To write some more code with another tutorial, take a look at Create a Go module.

随着快速介绍,你安装了Go并学习了一些基本知识。要通过另一个教程编写更多代码,请看创建一个Go模块。