Go Language Primer

Source: Internet
Author: User

A Go Environment installation deployment
Chinese go Documentation and installation package: HTTPS://STUDYGOLANG.COM/DL
#windows安装下载软件包 Next Installation Complete
Use the MSI file and follow the prompts to install the Go tool. By default, the Setup program uses the C:\Go directory. The installer should set the directory in the window's PATH environment variable C:\Go\bin . After restarting, open a command prompt to verify that the change is in effect.
Verifying the installation Results
F:\worksp\golangCreate a test.go go file in. Write and save the following code into the test.go file.
package mainimport "fmt"func main() { fmt.Println("Hello, World!")}


Download the installation package using binary mode in the #Linux extract Add environment variable


Export path= $PATH:/usr/local/go/bin

Second: The first Go program code

" FMT " Func Main () {    var"egrep"    fmt. Printf ("Hell World Welcome Learn go  ", name)}

#以上代码的解释

  • If you are compiling the code into an executable program, the package must be main: the beginning of the program
  • If it is to compile the code into a library, then the package has no restrictions
  • All the code in the Go program should be described in a package
  • FMT is a system library FMT in go. Println () can print the output and wrap the FMT. Print () prints FMT. Printf () printing supports formatted output
  • If you want to run a program command go run #先编译后执行
  • There is only one main function in an executable program
  • #注释说明
  • Single-line comment//
  • Multiline Comment/* */

#执行的结果如下

d:\PROJECT-practice under \src\day01>go Build hellworld.god:\project-class practice \src\day01>hellworld.exehell World Welcome Learn go egrepd:\project-practice \src\day01>go run Hellworld.gohell World Welcome Learn Go egrepd:\project-Class practice \src\ Day01>
Three GO command summary
Go Run program name #先编译后执行  go build  #编译源代码为二进制的文件 under  Windows translated into program name  . EXE Linux translated into executable file go install  /bin/ file directory under    gofmt-w. #将代码格式化   such as: The following code indentation is not very perfect, we can use the command gofmt-w.

Four: Simple introduction to the variable of Go language

Define a variable keyword var

var variable name variable type #如 var name = "Egrep" #切记在go里面 double quotes inside are string types, single quotes are character types they are different.

Defining a variable and assignment can be done in one step by: variable name: = value #如: Name: = "Egrep" can also be var name string = "Egrep" or

var (name = "Egrep" age = 18)

Attention:

The variables that are defined in the go language, or the packages that are referenced, must be used, or they will be error, as shown below

" FMT " Func Main () {    var"egrep"    fmt. Printf ("Hell World Welcome Learn go   ")}

#编译执行的时候报错

d:\PROJECT-Practice \src\day01>go Run Hellworld.go
# command-line-arguments
. \hellworld.go:6:6:name declared and not used

Go Language Primer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.