MindMap Gallery GO basic syntax
Describes the syntax used when learning the GO language, with code attached. It can be used as an introduction to comparative learning of GO language. If there are any additions later, a new map will be published on the work page.
Edited at 2024-01-23 15:35:28This organizational chart, created using EdrawMax, illustrates the hierarchical structure of the Tesla Supercharger Network team. It showcases the chain of command starting from the Chief Executive Officer (CEO) down to various department heads and their respective team members. Each individual's role is clearly defined, showing how different functions such as planning, project construction, power & energy, and operations & service are organized to efficiently manage and expand the Supercharger network globally.
This 2026 Event Countdown Calendar, specifically highlighting the Christmas countdown and created via EdrawMax, presents a detailed monthly breakdown. Each month features a grid layout with a countdown mechanism towards significant events, especially Christmas. The use of red for countdown numbers creates a striking contrast, making it easy to track the days remaining until the big event. It's a perfect tool for those eagerly anticipating Christmas and wanting to plan related activities in advance.
This 2026 Holiday Planning Calendar, crafted with EdrawMax, offers a well-organized monthly view. Each month displays a grid of dates, with major holidays clearly marked. The color-coded design, using red and blue accents, helps distinguish different months and holidays at a glance. It serves as an excellent resource for planning vacations, family gatherings, or any events around holiday periods, ensuring you can make the most of your time off throughout the year.
This organizational chart, created using EdrawMax, illustrates the hierarchical structure of the Tesla Supercharger Network team. It showcases the chain of command starting from the Chief Executive Officer (CEO) down to various department heads and their respective team members. Each individual's role is clearly defined, showing how different functions such as planning, project construction, power & energy, and operations & service are organized to efficiently manage and expand the Supercharger network globally.
This 2026 Event Countdown Calendar, specifically highlighting the Christmas countdown and created via EdrawMax, presents a detailed monthly breakdown. Each month features a grid layout with a countdown mechanism towards significant events, especially Christmas. The use of red for countdown numbers creates a striking contrast, making it easy to track the days remaining until the big event. It's a perfect tool for those eagerly anticipating Christmas and wanting to plan related activities in advance.
This 2026 Holiday Planning Calendar, crafted with EdrawMax, offers a well-organized monthly view. Each month displays a grid of dates, with major holidays clearly marked. The color-coded design, using red and blue accents, helps distinguish different months and holidays at a glance. It serves as an excellent resource for planning vacations, family gatherings, or any events around holiday periods, ensuring you can make the most of your time off throughout the year.
GO basic syntax
basic grammar
main function
package declaration
Can be different from the name directory
The declaration of the test file can be added with the _test suffix
The declarations of .go files in the same directory must be consistent, and the declarations of test files must also be consistent.
Accessibility
Capitalized means it can be accessed outside the package.
Lowercase can only be accessed within the package
basic type
int family (can express positive and negative numbers)
int
The number of bytes used by int depends on the CPU
int8
1 byte
int16
2 bytes
int32
4 bytes
int64
8 bytes
unit family (unsigned integer) (can only express positive numbers)
uint
How many bytes are used by uint depends on the CPU
uint8
1 byte
uint16
2 bytes
uint32
4 bytes
uint64
8 bytes
float family
float32
4zijie
float64
8 bytes
string
For splicing
Auxiliary usage using strings package
The double quotes "" inside Println() need to be escaped, otherwise it will cause output errors. When escaping, you can write the content to be output and then copy it into the double quotes, so that the compiler can automatically escape
Println() can also use backticks ` `, and newlines can be added inside the backticks.
When splicing strings, you cannot connect numbers. You need to convert the numbers into strings first and then splice them. Use strconv.Itoa(123) to convert 123 into a string.
What you get using the function len() is the byte length of the string, not the number of characters. Use utf8.RuneCountInString() to get the number of characters
byte type
It is bytes, essentially uint8, which is also used to represent ASCII codes. The corresponding operations are in the bytes package.
[ ]byte slices can be converted to and from strings.
var a [ ]byte = 'a' When assigning a value using single quotes, you can only use a single character. At this time, the ASCII code value of a is 97.
var a [ ]byte = "hello" can be assigned to a string when using double quotes
bool type
And: (a && b)
OrOr:( a || b)
Negation: (!a)
computation
The math package has more auxiliary uses
Hold down the command and click on the package function to jump into the package to see the relevant explanations.
Both sides of the operation must be of the same type. Int and int64 cannot be operated together and must be converted to the same type before operation.
Integers and integer operation results are also integers. If you want to get accurate values, you need to convert them to floating point types and then calculate.
variable
var a int = 123
a := 123
declare and assign
GO type inference
Can only be used for local variables
constant
const a int = 123
You can infer it yourself without the type.
Cannot modify
iota usage
Control constant initialization
However, using iota’s mathematical operations, including displacement operations
function
definition
keyword func
Function name
parameter list
Parameters can have names or not.
Parameters of the same type that are close together can declare their types together.
return value
Allow multiple return values
The return value can have a name, and the scope of the name is the entire function
recursion
Getting Started with Functional Styles
function as variable
local function
function as return value
anonymous function
Closure
context function
functions as types
indefinite parameters
last parameter
Equivalent to using slices
defer
First in, last out
Principles for determining values
Passed as a parameter: determined when defining
Introduced as a closure: determined when used
Modify return value
Only named return values can be modified
Implementation principle
control structure
for
for range loop
for i loop
for condition loop
switch statement
There can be a default branch
No need to break
Compilation can be switched through instructions
1
Naming rules
Capitalization controls accessibility
camel case nomenclature
Support type inference
Recommended Use