当前位置:网站首页>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
边栏推荐
猜你喜欢
How are the open source Netease cloud music API projects implemented?
Leetcode59. spiral matrix II (medium)
Setting and using richview trvstyle template style
(4) Web security | penetration testing | network security web site source code and related analysis
leetcode6109. 知道秘密的人数(中等,周赛)
Path analysis model
leetcode59. 螺旋矩阵 II(中等)
Detailed explanation | detailed explanation of internal mechanism of industrial robot
SEO学习的最好方式:搜索引擎
杰理之BLE【篇】
随机推荐
数字IC设计笔试题汇总(一)
navicat如何导入MySQL脚本
Cookie技术&Session技术&ServletContext对象
开源的网易云音乐API项目都是怎么实现的?
杰理之如若需要大包发送,需要手机端修改 MTU【篇】
Zhongqing reading news
【mysql学习笔记29】触发器
Introduction to the basics of network security
chrome查看页面fps
Refer to how customer push e-commerce does content operation
The differences and advantages and disadvantages between cookies, seeion and token
Short video, more and more boring?
Top test sharing: if you want to change careers, you must consider these issues clearly!
leetcode841. Keys and rooms (medium)
Bio model realizes multi person chat
How are the open source Netease cloud music API projects implemented?
Idea console color log
配置树莓派接入网络
Proteus -- Serial Communication parity flag mode
变量的命名规则十二条