摘要: Channels can bebuffered. Provide the buffer length as the second argument tomaketo initialize a buffered channel:ch := make(chan int, 100)Sends to a b... 阅读全文
posted @ 2014-10-28 23:44 wuhn 阅读(189) 评论(0) 推荐(0) 编辑
摘要: Channels are a typed conduit through which you can send and receive values with the channel operator,<-.ch <- v // Send v to channel ch.v := <-ch ... 阅读全文
posted @ 2014-10-28 23:40 wuhn 阅读(135) 评论(0) 推荐(0) 编辑
摘要: The next section covers Go's concurrency primitives.A Tour of GoGoroutinesAgoroutineis a lightweight thread managed by the Go runtime.go f(x, y, z)sta... 阅读全文
posted @ 2014-10-28 23:32 wuhn 阅读(164) 评论(0) 推荐(0) 编辑
摘要: /* Exercise: Loops and Functions #43 */package main import ( "fmt" "math") func Sqrt(x float64) float64 { z := float64(2.) s := float64(0)... 阅读全文
posted @ 2014-10-28 23:29 wuhn 阅读(782) 评论(0) 推荐(0) 编辑
摘要: package mainimport ( "io" "os" "strings" "fmt")type rot13Reader struct { r io.Reader}func (rot13 rot13Reader)Read(p []byte) (n int, err... 阅读全文
posted @ 2014-10-28 23:27 wuhn 阅读(484) 评论(0) 推荐(0) 编辑
摘要: Remember the picture generator you wrote earlier? Let's write another one, but this time it will return an implementation ofimage.Imageinstead of a sl... 阅读全文
posted @ 2014-10-28 23:09 wuhn 阅读(400) 评论(0) 推荐(0) 编辑
摘要: Package imagedefines theImageinterface:package imagetype Image interface { ColorModel() color.Model Bounds() Rectangle At(x, y int) color.Col... 阅读全文
posted @ 2014-10-28 22:59 wuhn 阅读(130) 评论(0) 推荐(0) 编辑
摘要: Implement the following types and define ServeHTTP methods on them. Register them to handle specific paths in your web server.type String stringtype S... 阅读全文
posted @ 2014-10-28 22:57 wuhn 阅读(454) 评论(0) 推荐(0) 编辑
摘要: Package httpserves HTTP requests using any value that implementshttp.Handler:package httptype Handler interface { ServeHTTP(w ResponseWriter, r *Re... 阅读全文
posted @ 2014-10-28 22:47 wuhn 阅读(143) 评论(0) 推荐(0) 编辑
摘要: Copy yourSqrtfunction from the earlier exercises and modify it to return anerrorvalue.Sqrtshould return a non-nil error value when given a negative nu... 阅读全文
posted @ 2014-10-28 20:41 wuhn 阅读(554) 评论(0) 推荐(0) 编辑
摘要: An error is anything that can describe itself as an error string. The idea is captured by the predefined, built-in interface type,error, with its sing... 阅读全文
posted @ 2014-10-28 20:23 wuhn 阅读(133) 评论(0) 推荐(0) 编辑
摘要: A type implements an interface by implementing the methods.There is no explicit declaration of intent.Implicit interfaces decouple implementation pack... 阅读全文
posted @ 2014-10-28 20:08 wuhn 阅读(238) 评论(0) 推荐(0) 编辑
摘要: An interface type is defined by a set of methods.A value of interface type can hold any value that implements those methods.Note:The code on the left ... 阅读全文
posted @ 2014-10-28 20:00 wuhn 阅读(125) 评论(0) 推荐(0) 编辑
摘要: Methods can be associated with a named type or a pointer to a named type.We just saw twoAbsmethods. One on the*Vertexpointer type and the other on the... 阅读全文
posted @ 2014-10-28 19:34 wuhn 阅读(275) 评论(0) 推荐(0) 编辑
摘要: In fact, you can define a method onanytype you define in your package, not just structs.You cannot define a method on a type from another package, or ... 阅读全文
posted @ 2014-10-28 18:59 wuhn 阅读(114) 评论(0) 推荐(0) 编辑
摘要: Go does not have classes. However, you can define methods on struct types.Themethod receiverappears in its own argument list between thefunckeyword an... 阅读全文
posted @ 2014-10-28 18:54 wuhn 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 打开相机://先设定sourceType为相机,然后判断相机是否可用(ipod)没相机,不可用将sourceType设定为相片库 UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCa... 阅读全文
posted @ 2014-10-28 17:04 wuhn 阅读(190) 评论(0) 推荐(0) 编辑
摘要: PhoneGap 和 Cordova的关系阐述是PhoneGap贡献给Apache后的开源项目,是从PhoneGap中抽出的核心代码,是驱动PhoneGap的核心引擎。你可以把他想象成类似于Webkit和Google Chrome的关系。Apache Cordova is an open-sourc... 阅读全文
posted @ 2014-10-28 15:39 wuhn 阅读(205) 评论(0) 推荐(0) 编辑
摘要: To Install, ensure that you have NodeJS installed, then open your commandline and run the following:$ sudo npm install -g phonegap Once ins... 阅读全文
posted @ 2014-10-28 15:32 wuhn 阅读(164) 评论(0) 推荐(0) 编辑
摘要: In my app, I am loading a resource heavy view that takes about 1 to 2 seconds to load. So I am loading it in a separate thread like this:hud = [[MBPro... 阅读全文
posted @ 2014-10-28 10:12 wuhn 阅读(359) 评论(0) 推荐(1) 编辑