关键字
defer
->或<- 管道
为什么go要给返回值命名
https://www.cnblogs.com/baiyuxiong/p/4325837.html
go中的interface
接口和结构体可以这么用
- 在一个函数中传入结构体,调用时可以直接使用[结构体的实力].[函数名]的方法调用函数。
package main
import (
"fmt"
)
type Phone interface {
call()
}
type NokiaPhone struct {
}
func (nokiaPhone NokiaPhone) call() {
fmt.Println("I am Nokia, I can call you!")
}
type IPhone struct {
}
func (iPhone IPhone) call() {
fmt.Println("I am iPhone, I can call you!")
}
func main() {
var phone Phone
phone = new(NokiaPhone)
phone.call()
phone = new(IPhone)
phone.call()
}
beego
函数
Go语言函数声明语法:函数名之前括号中的内容
前面的对象指针表示函数可以成为这个对象的暂时的成员函数的意思吧
package main
import "fmt"
type Mutatable struct {
a int
b int
}
func (m Mutatable) StayTheSame() {
m.a = 5
m.b = 7
}
func (m *Mutatable) Mutate() {
m.a = 5
m.b = 7
}
func main() {
m := &Mutatable{0, 0}
fmt.Println(m)
m.StayTheSame()
fmt.Println(m)
m.Mutate()
fmt.Println(m)
&{0 0}
&{0 0}
&{5 7}