当前位置:网站首页>The way to learn go (I) the basic introduction of go to the first HelloWorld
The way to learn go (I) the basic introduction of go to the first HelloWorld
2022-07-06 07:18:00 【Tiger up】
1.go Installation and environment variable configuration :
Get into https://golang.google.cn/dl/
choice go Install the version and system of
Set up after installation GOHOME, And will GOHOME/bin Add to environment variables
Enter... When finished go Verify that the installation was successful
2.go The advantages of :
1. Bring their own gc.
2. Static compilation , After compiling , Throw the server to run directly .
3. Simple thoughts , No inheritance , polymorphic , Class etc. .
4. Rich libraries and detailed development documents .
5. The syntax layer supports concurrency , And those with synchronous concurrency channel type , Make concurrent development very convenient .
6 Simple grammar , Improve development efficiency , At the same time, it improves the readability and maintainability of the code .
7. Super simple cross compilation , Just change the environment variable .
3.go Characteristics of :
1. Automatic immediate recycling .
2. Richer built-in types .
3. Function returns multiple values .
4. Error handling .
5. Anonymous functions and closures .
6. Types and interfaces .
7. Concurrent programming .
8. Reflection .
9. Language interactivity
4.go file name
be-all go The source code is based on “.go” ending .
5.go Language naming of :
1.Go Function of 、 Variable 、 Constant 、 Custom type 、 package (package) The following rules apply to the naming of :
1) The first character can be arbitrary Unicode Character or underscore
2) The remaining characters can be Unicode character 、 Underline 、 Numbers
3) There is no limit to the length of characters
2.Go Only 25 Key words
break default func interface select case
defer go map struct chan else
goto package switch const fallthrough if
range type continue for import return
var
3.Go also 37 A reserved word
Constants: true false iota nil Types: int int8 int16 int32
int64
uint uint8 uint16 uint32 uint64 uintptr
float32 float64 complex128 complex64
bool byte rune string error Functions: make len cap new append copy close delete
complex real imag
panic recover
4. visibility :
1) Declared inside a function , Is the local value of the function , similar private
2) Declared outside the function , Is visible to the current package ( All in the package .go All files are visible ) Global value of , similar protect
3) Declared outside the function and capitalized is the global value visible to all packages , similar public
6.Go Language statement :
There are four main ways to declare :
var( Declare variables ), const( declare constant ), type( Declaration type ) ,func( Declare functions )
Go The program is stored in multiple .go In file , The first line of the file is package XXX Statement , It is used to indicate which package the file belongs to (package),package It's a statement import Statement , Next comes the type , Variable , Constant , Declaration of functions .
7.Go Project construction and compilation
One Go The project mainly includes the following three directories :
src: Source code file
pkg: Package file
bin: relevant bin file
8.Go One of the first helloworld
newly build goproject
goproject Under the new src、pkg、bin
open src newly build helloworld.go, And enter the following
package main
import "fmt"
func main(){
fmt.Println("hello world")
}
Command line window execution go build
Generate a helloworld Of exe file
Execute this file to print hello world
边栏推荐
- SSM学习
- Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- leetcode704. 二分查找(查找某个元素,简单,不同写法)
- 【mysql学习笔记30】锁(非教程)
- Introduction to the basics of network security
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- First knowledge of OpenGL es learning (1)
- Raspberry pie serial port login and SSH login methods
- The psychological process from autojs to ice fox intelligent assistance
猜你喜欢
这个高颜值的开源第三方网易云音乐播放器你值得拥有
Establishment and operation of cloud platform open source project environment
杰理之如若需要大包发送,需要手机端修改 MTU【篇】
Oracle database 11gr2 uses TDE transparent data encryption to report an error ora28353. If you run to close the wallet, you will report an error ora28365. If you run to open the wallet, you will repor
3. Business and load balancing of high architecture
Leetcode 78: subset
Leetcode59. spiral matrix II (medium)
学go之路(一)go的基本介绍到第一个helloworld
变量的命名规则十二条
Solution to the problem of breakthrough in OWASP juice shop shooting range
随机推荐
Internal and external troubles of "boring ape" bayc
OpenJudge NOI 2.1 1661:Bomb Game
[some special grammars about C]
剪映的相关介绍
[JDBC] quick start tutorial
L'auteur est mort? Ai utilise l'art pour conquérir l'humanité
leetcode35. 搜索插入位置(简单,找插入位置,不同写法)
Twelve rules for naming variables
(4) Web security | penetration testing | network security web site source code and related analysis
3. Business and load balancing of high architecture
leetcode6109. 知道秘密的人数(中等,周赛)
TypeScript void 基础类型
Arduino tutorial - Simon games
树莓派3B更新vim
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
leetcode841. Keys and rooms (medium)
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
Thought map of data warehouse construction
GET/POST/PUT/PATCH/DELETE含义
leetcode841. 钥匙和房间(中等)