当前位置:网站首页>go学习记录二(Window)
go学习记录二(Window)
2022-06-23 03:52:00 【韧小钊】
go学习20220523
go环境安装(window)
- 选择windows环境版本,下载地址同Linux

- 点击安装,指定安装目录

- 配置环境变量
win10安装完,自动生成了环境变量,如果没有,则需手动添加
- 验证环境
cmd–>go veriosn
开发工具安装
- 下载VScode开发工具
下载地址 - 安装go插件

- 设置go参数
打开设置(ctrl+,)–>搜索golang–>点击json编辑
"go.goroot": "D:\\Go\\bin",
"go.gopath":"F:\\worker_go"

- 安装相关依赖组件
go env -w GOPROXY=https://goproxy.cn
go install -v golang.org/x/tools/[email protected]

- 编写代码测试
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}

条件循环语句
- if语句
package main
import "fmt"
func main() {
/* 定义局部变量 */
var a int = 66
/* 判断条件 */
if a > 90 {
/* if 条件语句为 true 执行 */
if a == 100 {
/* if 条件语句为 true 执行 */
fmt.Println("完美" );
} else {
fmt.Println("优秀" );
}
} else if (a>80 && a<=90) {
fmt.Println("棒" );
} else {
fmt.Println("其它" );
}
}
修改变量值,进行测试
- switch
fallthrough会继续执行下一条case,且不会去判断其表达式是否为true
- for
if加上括号可以执行,和java写法一样,for不行,加上括号会报错
语言结构体
和Java很像啊
package main
import "fmt"
type Car struct {
brand string
speed float64
color string
}
func main() {
/* 不就是Java的构造函数创建对象嘛*/
fmt.Println(Car{
"奔驰",100.88,"黑色"})
fmt.Println(Car{
brand:"奔驰",speed:100.88})
/* Java的创建对象,属性set值*/
var Benchi Car /* 声明 Benchi 为 Car 类型 */
Benchi.brand="大奔"
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() {
/* 创建map */
var testMap map[string]string
/* 初始化map */
testMap = make(map[string]string)
testMap["Name"]="Tom"
testMap["face"]="big"
for m := range testMap {
fmt.Println(m, "值为", testMap [m])
}
for k,v := range testMap {
fmt.Println(k, "=", v)
}
}

- 多类型value,类型指定
package main
import "fmt"
func main() {
/* 创建map */
var testMap map[string]interface{
}
/* 初始化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)
}
}

数组切片
package main
import "fmt"
func main() {
/*数组,长度固定*/
shuzu := [3]int{
1,2,3}
fmt.Println("数组===========================")
for j := 0; j < 3; j++ {
fmt.Println(shuzu[j])
}
/*切片,动态数组,可以动态添加元素*/
var shuzu1 = make([]int,3)//指定切片初始长度(数组长度)
shuzu1 = []int{
1,2,3}
fmt.Println("切片===========================")
shuzu1 = append(shuzu1,4)//追加元素
shuzu1 = append(shuzu1,5,6,7)
for j := 0; j < len(shuzu1); j++ {
fmt.Println(shuzu1[j])
}
}

边栏推荐
- PCB -- bridge between theory and reality
- Gson typeadapter adapter
- OGNL Object-Graph Navigation Language
- 2 万字 + 20张图|细说 Redis 九种数据类型和应用场景
- How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!
- With the arrival of intelligent voice era, who is defining AI in the new era?
- const理解之二
- Amazing tips for using live chat to drive business sales
- Icer Skill 02makefile script Running VCS Simulation
- Reinstallation of cadence16.3, failure and success
猜你喜欢

Actual combat | multiple intranet penetration through Viper

What are the types of independent station chat robots? How to quickly create your own free chat robot? It only takes 3 seconds!

ADR electronic transmission EDI solution of national adverse drug reaction monitoring center

How can mushrooms survive a five-year loss of 4.2 billion yuan?

Dsp7 environment

独立站聊天机器人有哪些类型?如何快速创建属于自己的免费聊天机器人?只需3秒钟就能搞定!

OGNL Object-Graph Navigation Language

Abnova LiquidCell-负富集细胞分离和回收系统

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

Abnova fluorescent dye 510-m streptavidin scheme
随机推荐
PCB -- bridge between theory and reality
Common concepts and terms in offline warehouse modeling
Abnova actn4 purified rabbit polyclonal antibody instructions
Cve-2019-14287 (sudo right raising)
Thinkphp6 template replacement
Amazing tips for using live chat to drive business sales
Reinstallation of cadence16.3, failure and success
欢迎使用CSDN-markdown编辑器
电流继电器HDL-A/1-110VDC-1
【论文阅读】Semi-Supervised Learning with Ladder Networks
win10查看my.ini路径
ICER skills 03design compile
Pads and flash symbols in cadence
STL tutorial 3- exception mechanism
Can bus Basics
Abnova 荧光染料 555-C3 马来酰亚胺方案
Freemodbus parsing 1
Laravel 8.4 routing problem. At the end is the cross reference table on the left side of the editor, which can be understood by Xiaobai
Examples of corpus data processing cases (part of speech encoding, part of speech restoration)
Abnova PSMA磁珠解决方案