Go interface

我们知道 Golang 中有两种方法:值方法和指针方法

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
type person struct{}

func (p *person) Speaker() {
	fmt.Println("Hello.")
}

type fox struct{}

func (f fox) Speaker() {
	fmt.Println("firefox.")
}

官方对函数的调用规则说明为: A method call x.m() is valid if the method set of (the type of) x contains m and the argument list can be assigned to the parameter list of m. If x is addressable and &x’s method set contains m, x.m() is shorthand for (&x).m().

Go的IO入门:Reader与Writer

将数据在不同地方倒腾是 golang 最常见的应用模式了,IO 相关的话题是如何写好 golang 避不开的话题。接下来,本文将对 golang 生态中的 IO 模块进行介绍。

Go的Context包解析

context包提供了以下功能:传递 Key-Value 值、取消信号、超时时间。由于 context 可以被安全的传递给任意数量的 goroutine,context 常被用于控制并发操作。

分布式系统-RAFT实现笔记

Mit6.824-Lab3A 实现笔记

本次实验为实现Raft中的选举部分,在实现时除了要完全按照论文的Figure2实现节点状态以外。在实际编写代码时,以下部分曾经困扰了我,现在总结如下: