当前位置:网站首页>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
边栏推荐
- You deserve this high-value open-source third-party Netease cloud music player
- Hydra common commands
- JDBC learning notes
- 【mysql学习笔记30】锁(非教程)
- leetcode6109. 知道秘密的人数(中等,周赛)
- 微信公众号无限回调授权系统源码 全网首发
- 杰理之普通透传测试---做数传搭配 APP 通信【篇】
- Oracle column to row -- a field is converted to multiple rows according to the specified separator
- 作者已死?AI正用艺术征服人类
- TS Basics
猜你喜欢

LeetCode 78:子集

NiO programming introduction

1189. Maximum number of "balloons"

Cif10 actual combat (resnet18)

首发织梦百度推送插件全自动收录优化seo收录模块

树莓派3B更新vim

Oracle column to row -- a field is converted to multiple rows according to the specified separator

Leetcode59. spiral matrix II (medium)

Setting and using richview trvstyle template style

杰理之BLE【篇】
随机推荐
1189. Maximum number of "balloons"
TypeScript 接口属性
Cookie技术&Session技术&ServletContext对象
How are the open source Netease cloud music API projects implemented?
Applied stochastic process 01: basic concepts of stochastic process
OpenJudge NOI 2.1 1661:Bomb Game
MPLS experiment
Short video, more and more boring?
Proteus -- Serial Communication parity flag mode
Crawling exercise: Notice of crawling Henan Agricultural University
Lesson 12 study notes 2022.02.11
supervisor 使用文档
Multithreading and concurrent programming (2)
杰理之普通透传测试---做数传搭配 APP 通信【篇】
leetcode841. Keys and rooms (medium)
Leetcode59. spiral matrix II (medium)
【mysql学习笔记30】锁(非教程)
位运算异或
剪映的相关介绍
SSM学习