Golang study notes (1): Introduction

Time:2021-7-13

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
reflex
Language interactivity

High performance / efficient development

install

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:
bin/
    |- mathapp
pkg/
    |- Platform name
        |- xxx.a
src/
    |- mathapp
        |- main.go

Helloworld

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”)
}

//Operation
$go run hello.go

$go build hello.go
$./hello

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

debugging

Using GDB to debug, go language has built-in

Copy codeThe code is as follows:
list
break
delete
backtrace
info
print
whatis
next
continue
set variable

Editor Settings

vim

Other supplements
notes

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

Import multiple packages

Copy codeThe code is as follows:
import (
    “fmt”
    “os”
)

Call the function in the package

Copy codeThe code is as follows:
<packageName>.<Function>

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 […]