商君

导航

2018年10月23日 #

Go Example--panic

摘要: ```go package main import "os" func main() { //panic会中断程序执行,在此处一直往上抛panic,需要上游的recover来捕获 panic("a problem") _, err := os.Create("/tmp/file") if err != nil { panic(err) } } ``` 阅读全文

posted @ 2018-10-23 16:07 漫步者01 阅读(103) 评论(0) 推荐(0)

Go Example--自定义排序

摘要: ```go package main import ( "fmt" "sort" ) //定义类型别名 type ByLength []string func (s ByLength) Len() int { return len(s) } func (s ByLength) Swap(i, j i 阅读全文

posted @ 2018-10-23 15:57 漫步者01 阅读(419) 评论(0) 推荐(0)

Go Example--排序

摘要: ```go package main import ( "fmt" "sort" ) func main() { strs := []string{"c", "a", "b"} //排序函数 sort.Strings(strs) fmt.Println("Strings:", strs) ints := []int{7, 2, 4} //排序函数 sort.Ints(ints... 阅读全文

posted @ 2018-10-23 15:46 漫步者01 阅读(117) 评论(0) 推荐(0)

Go Example--状态协程

摘要: ```go package main import ( "fmt" "math/rand" "sync/atomic" "time" ) type readOp struct { key int resp chan int } type writeOp struct { key int val in 阅读全文

posted @ 2018-10-23 15:41 漫步者01 阅读(234) 评论(0) 推荐(0)