![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Golang
琼黍
人生永远不会是一场梦,胜梦半子安惧天
展开
-
Golang--Channel基础
1.Channel简介Channel是Go中的一个核心类型,你可以把它看成一个管道,通过它并发核心单元就可以发送或者接收数据进行通讯。 它的操作符是箭头<-。ch := make(chan int, 100)defer close(ch)ch <- v //发送值v到Channel ch中v := <-ch //从Channel ch中接收数据,并将数据赋值给vv, ok := <-ch原创 2017-05-09 18:22:16 · 442 阅读 · 0 评论 -
Golang--Goroutines
Thread-per-connection模型不够有效,在诸多比较合适的范式中,Communicating Sequential Processes(顺序通信处理,CSP)还有一个叫做message passing-model(消息传递)。 协程是根据一个或多个线程的可用性,映射(多路复用,执行于)在他们之上的;协程调度器在Go运行时很好的完成了这个工作。协程工作在相同的地址空间中,所以共享一定是原创 2017-05-10 09:38:31 · 372 阅读 · 0 评论 -
Goblog--Arrays,slices(and strings):The mechanics of 'append'
ArraysArrays are not often seen in Go programs because the size of an array is part of its type, which limits its expressive power. The declaration var buffer [256]byte declares the variable buffer翻译 2017-05-10 09:41:21 · 543 阅读 · 0 评论 -
Goblog--strings,bytes,runes and characters in Go
Introduction To use strings well requires understanding not only how they work but also the difference between a byte,a character,and a rune,the difference between Unicode and UTF-8,the difference bet翻译 2017-05-10 09:42:19 · 365 阅读 · 0 评论 -
Golang--database/sql
导入driverimport ( "database/sql" _ "github.com/go-sql-driver/mysql")连接DBdb, err := sql.Open("mysql", "user:password@tcp(127.0.0.1:3306)")if err != nil { log.Fatal(err)}defer db.Clos原创 2017-05-10 09:44:22 · 427 阅读 · 0 评论 -
Golang--interface断言
一个interface类型的变量varI中可以包含任何类型的值,必须有一种方式来检测它的动态类型,即运行时在变量存储中的值的实际类型。通常我们可以使用类型断言来测试在某个时刻varI是否包含类型T的值: v,ok := varI.(T) #varI必须是一个interface变量 如果转换合法,v是varI转换到类型T的值,ok是true;否则v是类型T的零值,ok是false。 接口的转换遵原创 2017-05-10 09:45:44 · 1424 阅读 · 0 评论 -
Golang--string操作
string到int int, err := strconv.Atoi(string)string到int64 int64, err := string.ParseInt(string, 10, 64)int到string string := strconv.Itoa(int)int64到string string := strconv.FormatInt(int64, 10)Has原创 2017-05-10 09:46:43 · 10204 阅读 · 1 评论