绪论
学习目标:高高手
为什么冯诺依曼体系架构经久不衰:解耦的思想
Go语言体系
初识Go
Go语言特性
环境准备
Go类型系统
类型体系
Hello Word常见的十种写法:
package main
import (
"fmt"
"time"
)
type HelloWorld struct {
value string
}
type ShowHello interface {
Print1()
}
func (hw HelloWorld) Print1() {
fmt.Println(hw.value)
}
func BiBao() {
var str = "hello world!"
f := func() {
fmt.Println(str)
}
f()
}
func TestChan(ch <-chan string) {
for v := range ch {
fmt.Print(v)
}
}
func main() {
fmt.Println("第一种:直接常量")
fmt.Println("hello world!")
fmt.Println("第二种:格式化常量")
fmt.Printf("%s\n", "hello world!")
fmt.Println("第三种:直接变量")
var str = "hello world!"
fmt.Println(str)
fmt.Println("第四种:数字转义")
fmt.Printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!')
fmt.Printf("%c%c%c%c%c%c%c%c%c%c%c%c\n", 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33)
fmt.Println("第五种:切片实现")
var slice = make([]string, 0)
slice = append(slice, "hello")
slice = append(slice, " ")
slice = append(slice, "world")
slice = append(slice, "!")
var str2 string
for _, s := range slice {
str2 += s
}
fmt.Println(str2)
fmt.Println("第六种:map实现")
var m1 = map[int]string{
1: "hello",
2: "world!",
}
fmt.Printf("%s %s\n", m1[1], m1[2])
fmt.Println("第七种:结构体实现")
hw := HelloWorld{value: "hello world!"}
fmt.Println(hw.value)
fmt.Println("第八种:接口实现")
var sh ShowHello = hw
sh.Print1()
fmt.Println("第九种:闭包实现")
BiBao()
fmt.Println("第十种:channel实现")
var ch = make(chan string, 8)
go TestChan(ch)
ch <- "hello "
ch <- "world!"
time.Sleep(time.Second * 3)
}
C:\Users\henry.shaw\AppData\Local\JetBrains\GoLand2023.3\tmp\GoLand\___go_build_helloword_go.exe
第一种:直接常量
hello world!
第二种:格式化常量
hello world!
第三种:直接变量
hello world!
第四种:数字转义
104,101,108,108,111,32,119,111,114,108,100,33
hello world!
第五种:切片实现
hello world!
第六种:map实现
hello world!
第七种:结构体实现
hello world!
第八种:接口实现
hello world!
第九种:闭包实现
hello world!
第十种:channel实现
hello world!
Process finished with the exit code 0
数据类型
常量
变量
数值型运算