Golang study notes (1): Introduction


The main features of go language

Copy codeThe code is as follows:
Automatic garbage collection
Richer built in types
Function multiple return values
error handling
Anonymous functions and closures
Types and interfaces
Concurrent programming
Language interactivity

High performance / efficient development


Installation instruction addresshttp://golang.org/doc/install

Package download addresshttps://code.google.com/p/go/downloads/list

Confirm whether the installation is successful

Copy codeThe code is as follows:
Go version / / view version

Environment variable settings

Overall directory structure

Through the package organization, only the package named main can contain the main function

A program has and only has one main package

Import other non main packages through import keyword

Copy codeThe code is as follows:
    |- mathapp
    |- Platform name
        |- xxx.a
    |- mathapp
        |- main.go


Copy codeThe code is as follows:
Package main / / declare the package of the file

import {
    ” FMT “/ / import package, which cannot contain unused package, otherwise compilation error will occur
Func main() {/ / entry function, no parameter, no return value
    fmt.Println(“hello world”)

$go run hello.go

$go build hello.go

Go command

View with command line

go help

Copy codeThe code is as follows:
Go build compilation
Go clean removes the compiled files in the current source code package
Go FMT format code
Go get remote code package dynamically
Go install generates the result file and sends the compiled result to $gopath / PKG or $gopath / bin
Go test executable file for running test
go doc    Godoc – HTTP =: 8080 view documents

Go fix fixes old version code to new version
Go version view the current version
Go env view the environment variables of the current go
Go list lists all currently installed packages
Go run compiles and runs the go language program


Using GDB to debug, go language has built-in

Copy codeThe code is as follows:
set variable

Editor Settings


Other supplements

Copy codeThe code is as follows:
//One way
/*—- * / multiline

Import multiple packages

Copy codeThe code is as follows:
import (

Call the function in the package

Copy codeThe code is as follows:

Recommended Today

To CSS search for a problem when a fixed item starts:/ a>

Front wheel For the item sent ц It’s going to be the same as the meeting. We’re going to talk about the reason why we’re going to be the same as the fix for the part we’re talking about in the same way. It’s the same reason that we’re going to have a meeting with […]