SoFunction
Updated on 2025-03-05

Golang study notes (I): Introduction

The most important feature of Go

Copy the codeThe code is as follows:

Automatic garbage collection
More richer built-in types
Functions return values
Error handling
Anonymous functions and closures
Types and interfaces
Concurrent programming
reflection
Language Interaction

High performance/efficient development

Install

Installation Instructions Address/doc/install

Package download address/p/go/downloads/list

Confirm whether the installation is successful

Copy the codeThe code is as follows:

go version //View version

Environment variable settings

Overall directory structure

Organized through package, only the main function can be included with the package name main

A program has and only one main package

Import other non-main packages through import keyword

Copy the codeThe code is as follows:

bin/
    |- mathapp
pkg/
|- Platform name
        |-
src/
    |- mathapp
        |-

Helloworld

Copy the codeThe code is as follows:

package main //Declare file package

import {
"fmt" //import package, cannot contain unused packages, otherwise there will be a compile error
}
func main() { //Entrance function, no parameters, no return value
    ("hello world")
}

//run
$go run

$go build
$./hello

go command

View with the command line

go help

Copy the codeThe code is as follows:

go build
go clean Removes the compiled file in the current source code package
go fmt format code
go get dynamically obtaining remote code packages
go install generates the result file and transfer the compiled result to $GOPATH/pkg or $GOPATH/bin
go test Executable file for running tests
go doc   godoc -http=:8080 View the document

go fix fix to fix the old version of the previous version of the code to the new version
go version to view the current version
go env to view the current go environment variables
go list list all currently installed packages
go run Compile and run go language program

debug

Use gdb for debugging, the go language is already built into

Copy the codeThe code is as follows:

list
break
delete
backtrace
info
print
whatis
next
continue
set variable

Editor Settings

vim

Other supplements
Comments

Copy the codeThe code is as follows:

//Single line
/* ----- */ Multiple lines

import multiple packages

Copy the codeThe code is as follows:

import (
    "fmt"
    "os"
)

Calling functions in packages

Copy the codeThe code is as follows:

<packageName>.<Function>