Golang study notes 1: introduction


The main features of the Go language

 Automatic garbage collection
 Richer built-in types
 The function returns multiple values
 Error handling
 Anonymous functions and closures
 Types and interfaces
 Concurrent programming
 reflection
 Linguistic interactivity
 A high performance / The efficient development

The installation

Installation instructions address http: / / golang org/doc/install

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

Verify that the installation was successful

go version // Check the version

Environment variable Settings

Overall directory structure

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

One program has only one main package

Import other non-main packages through the import keyword

bin/
    |- mathapp
pkg/
    |-  The platform of
        |- xxx.a
src/
    |- mathapp
        |- main.go

Helloworld

package main // declaratory package
import {
    "fmt" //import  Package, can not contain unused packages, otherwise the compilation error
}
func main() { // The entry function ,  No parameters, no return value
    fmt.Println("hello world")
}
// run
$go run hello.go
$go build hello.go
$./hello

go command

View from the command line

go help

go build  compile
go clean  Removes the build build file from the current source package
go fmt  Formatting code
go get  Get the remote code package on the fly
go install  Generate the results file and compile the good results 1 to $GOPATH/pkg or $GOPATH/bin
go test  Run the test executable
go doc   godoc -http=:8080  To view the document
go fix  Fix old version code to new version
go version View current version
go env  View the current go Environment variables
go list  Lists all current installations package
go run  Compile and run go Language program

debugging

Debugging with gdb, the go language is already built in

list
break
delete
backtrace
info
print
whatis
next
continue
set variable

Editor Settings

vim

Other supplementary annotation

// A single
/* ----- */  Multiple lines

import multiple packages

import (
    "fmt"
    "os"
)

Call the ground function in the package

<packageName>.<Function>