摘要:
package main import ( "fmt" "math" ) type Abser interface { Abs() float64 Abs2() float64 } func main() { var a Abser f := MyFloat(-math.Sqrt2) v := Ve 阅读全文
摘要:
package main import ( "fmt" "sync" "time" ) // SafeCounter is safe to use concurrently. type SafeCounter struct { mu sync.Mutex v map[string]int } // 阅读全文
摘要:
package main import ( "golang.org/x/tour/tree" "fmt" ) // Walk walks the tree t sending all values // from the tree to the channel ch. func Walk(t *tr 阅读全文
摘要:
无缓冲通道(阻塞通道) 写入后立即阻塞,需要另一个协程读取通道的数据后,才能继续执行。 通道操作符 ch <- v // Send v to channel ch. v := <-ch // Receive from ch, and // assign value to v. 无缓冲通道 ch := 阅读全文
摘要:
package main import "golang.org/x/tour/reader" type MyReader struct{} // TODO: Add a Read([]byte) (int, error) method to MyReader. func (m MyReader) R 阅读全文
摘要:
package main import ( "fmt" "strings" "strconv" ) type IPAddr [4]byte func (ip IPAddr) String() string{ array := make([]string, len(ip)) for i, b := r 阅读全文