当前位置:网站首页>Go learning record II (window)
Go learning record II (window)
2022-06-23 05:02:00 【Zhun Xiaozhao】
Catalog
go Study 20220523
go Environmental installation (window)
- choice windows Environment version , Download address is the same as Linux

- Click on the install , Specify the installation directory

- Configure environment variables
win10 installed , Automatically generated environment variables , without , You need to add it manually
- Verification environment
cmd–>go veriosn
Development tool installation
- download VScode development tool
Download address - install go plug-in unit

- Set up go Parameters
Open Settings (ctrl+,)–> Search for golang–> Click on json edit
"go.goroot": "D:\\Go\\bin",
"go.gopath":"F:\\worker_go"

- Install related dependent components
go env -w GOPROXY=https://goproxy.cn
go install -v golang.org/x/tools/[email protected]

- Write code tests
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}

Conditional loop statement
- if sentence
package main
import "fmt"
func main() {
/* Defining local variables */
var a int = 66
/* Judge the condition */
if a > 90 {
/* if The conditional statement is true perform */
if a == 100 {
/* if The conditional statement is true perform */
fmt.Println(" perfect " );
} else {
fmt.Println(" good " );
}
} else if (a>80 && a<=90) {
fmt.Println(" Great " );
} else {
fmt.Println(" Other " );
}
}
Change the value of the variable , To test 
- switch
fallthrough Will proceed to the next case, And will not judge whether the expression is true
- for
if Add parentheses to execute , and java In the same way ,for no way , Adding parentheses will cause errors
Language structure
and Java It's very similar
package main
import "fmt"
type Car struct {
brand string
speed float64
color string
}
func main() {
/* No, it is. Java Constructor to create objects */
fmt.Println(Car{
" Mercedes ",100.88," black "})
fmt.Println(Car{
brand:" Mercedes ",speed:100.88})
/* Java Create objects for , attribute set value */
var Benchi Car /* Statement Benchi by Car type */
Benchi.brand=" Big rush "
Benchi.speed=111.11
Benchi.color="red"
fmt.Println(Benchi.brand)
fmt.Println(Benchi.speed)
fmt.Println(Benchi.color)
}

map
- map[key type]value type
package main
import "fmt"
func main() {
/* establish map */
var testMap map[string]string
/* initialization map */
testMap = make(map[string]string)
testMap["Name"]="Tom"
testMap["face"]="big"
for m := range testMap {
fmt.Println(m, " The value is ", testMap [m])
}
for k,v := range testMap {
fmt.Println(k, "=", v)
}
}

- Multiple types value, Type designation
package main
import "fmt"
func main() {
/* establish map */
var testMap map[string]interface{
}
/* initialization map */
testMap = make(map[string]interface{
})
testMap["Name"]="Tom"
testMap["age"]=99
testMap["high"]=177.8
for k,v := range testMap {
fmt.Println(k, "=", v)
}
}

Array slice
package main
import "fmt"
func main() {
/* Array , Fixed length */
shuzu := [3]int{
1,2,3}
fmt.Println(" Array ===========================")
for j := 0; j < 3; j++ {
fmt.Println(shuzu[j])
}
/* section , The dynamic array , You can add elements dynamically */
var shuzu1 = make([]int,3)// Specify the initial length of the slice ( The length of the array )
shuzu1 = []int{
1,2,3}
fmt.Println(" section ===========================")
shuzu1 = append(shuzu1,4)// Additional elements
shuzu1 = append(shuzu1,5,6,7)
for j := 0; j < len(shuzu1); j++ {
fmt.Println(shuzu1[j])
}
}

边栏推荐
- Shadertoy basic teaching 02. Drawing smiling faces
- TabControl style of WPF basic control
- DSP7 环境
- OGNL Object-Graph Navigation Language
- Shadertoy basic teaching 01. Circle drawing (explanation of smoothstep() function)
- 怎样利用数据讲一个精彩故事?
- mysql json
- Freemodbus parsing 1
- Openjudge noi 1.13 51: ancient password
- STL教程3-异常机制
猜你喜欢

开发一年不到,来面试居然敢开口要20K,面完连8K都不想给~

怎样利用数据讲一个精彩故事?

Transformers中的动态学习率

Current relay hdl-a/1-110vdc-1

Cloud native database is in full swing, and the future can be expected

PaddlePaddle模型服务化部署,重新启动pipeline后出现报错,trt报错

Common concepts and terms in offline warehouse modeling

gson TypeAdapter 适配器

Mini Homer - can you get a remote map data transmission link for hundreds of yuan?

ICer技能03Design Compile
随机推荐
STL教程3-异常机制
Common concepts and terms in offline warehouse modeling
prometheus、influxdb2.2安装及flume_export下载编译使用
Transformers中的动态学习率
接收传来得文件并下载(简单用法)a标签
Non return to zero code NRZ
How to better organize the minimum web api code structure
The solution to prompt "this list creation could be rewritten as a list literal" when adding elements to the list using the append() method in pychart
ZK has a node reporting it is possible not running and the log has no obvious error
Halcon knowledge: binocular_ Discrimination knowledge
《微信小程序-基础篇》带你了解小程序的路由系统(二)
Receive incoming files and download (simple usage) a tag
dolphinscheduler 2.0.5 spark 任务测试总结(源码优化)
Abnova ACTN4纯化兔多克隆抗体说明书
AD9使用技巧拾遗
Ad9 tips
左值与右值
实战| 记一次借Viper来多重内网渗透
Abnova fluorescent dye 555-c3 maleimide scheme
ADR electronic transmission EDI solution of national adverse drug reaction monitoring center