当前位置:网站首页>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
边栏推荐
- 树莓派串口登录与SSH登录方法
- How to configure GUI guide development environment
- [JDBC] quick start tutorial
- TypeScript 函数定义
- TypeScript 接口属性
- 杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
- 学go之路(二)基本类型及变量、常量
- 呆错图床系统源码图片CDN加速与破解防盗链功能
- 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
- 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
猜你喜欢

杰理之BLE【篇】

NFT on fingertips | evaluate ambire on G2, and have the opportunity to obtain limited edition collections

leetcode1020. 飞地的数量(中等)

Multi attribute object detection on rare aircraft data sets: experimental process using yolov5

Solution to the problem of breakthrough in OWASP juice shop shooting range

Detailed explanation | detailed explanation of internal mechanism of industrial robot

数字IC设计笔试题汇总(一)

杰理之AD 系列 MIDI 功能说明【篇】

杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】

树莓派串口登录与SSH登录方法
随机推荐
Lesson 12 study notes 2022.02.11
“无聊猿” BAYC 的内忧与外患
word中如何删除某符号前面或后面所有的文字
巴比特 | 元宇宙每日必读:中国互联网企业涌入元宇宙的群像:“只有各种求生欲,没有前瞻创新的雄心”...
leetcode841. 钥匙和房间(中等)
Cookie技术&Session技术&ServletContext对象
On the world of NDK (2)
Go learning --- use reflection to judge whether the value is valid
杰理之如若需要大包发送,需要手机端修改 MTU【篇】
idea控制台彩色日志
Crawling exercise: Notice of crawling Henan Agricultural University
Openjudge noi 2.1 1749: Digital Square
【mysql学习笔记29】触发器
Is software testing outsourcing going or not? Three years' real outsourcing experience tells you
leetcode841. Keys and rooms (medium)
呆错图床系统源码图片CDN加速与破解防盗链功能
Solution to the problem of breakthrough in OWASP juice shop shooting range
数据仓库建设思维导图
LeetCode Algorithm 2181. 合并零之间的节点
杰理之需要修改 gatt 的 profile 定义【篇】