go

关键字

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}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值