Golang:基础图解
2017-12-05 本文已影响4人
与蟒唯舞
常用 go 命令
![](https://img.haomeiwen.com/i2733312/9a8f36436442b500.png)
编译 / 执行代码
![](https://img.haomeiwen.com/i2733312/c23fb1533e2e9db8.png)
包相关
![](https://img.haomeiwen.com/i2733312/b0e3d9544d50a99e.png)
![](https://img.haomeiwen.com/i2733312/4966d8273e181ee9.png)
![](https://img.haomeiwen.com/i2733312/73910e4daea7417f.png)
![](https://img.haomeiwen.com/i2733312/65d38ee94ff2797a.png)
![](https://img.haomeiwen.com/i2733312/690b92200d122bf9.png)
零值
![](https://img.haomeiwen.com/i2733312/28654e3c6cfb175b.png)
自定义类型
![](https://img.haomeiwen.com/i2733312/ca87351644297bf3.png)
函数接收者
![](https://img.haomeiwen.com/i2733312/d8e9b76dd26c4912.png)
![](https://img.haomeiwen.com/i2733312/462decf6172e0d04.png)
![](https://img.haomeiwen.com/i2733312/2ea9f136f534ccd3.png)
Now, any variable of type "deck" now get access to the "print" method.
package main
import "fmt"
type deck []string
/*
func (this deck) print() {}
func (self deck) print() {}
While the code is technically valid and will compile, we don't ever reference a receiver value as 'this' or 'self'
Go avoids any mention of 'this' or 'self'
*/
func (d deck) print() {
for i, card := range d {
fmt.Println(i, card)
}
}
func main() {
cards := deck{"Ace of Spades", "Two of Spades"}
cards.print()
}
切片
![](https://img.haomeiwen.com/i2733312/e3644732a7242d30.png)
![](https://img.haomeiwen.com/i2733312/d2655549c8108bdb.png)
字节切片
![](https://img.haomeiwen.com/i2733312/76a76d717fb61568.png)
![](https://img.haomeiwen.com/i2733312/6bd5214a4d3a32c3.png)