上一页 1 ··· 18 19 20 21 22 23 24 25 26 ··· 52 下一页
摘要: 代码示例: 004.struct类型 004.struct类型 1 type声明新类型 1 type声明新类型 1.1 type testInt func(int) bool // 声明了一个函数类型 1.1 type testInt func(int) bool // 声明了一个函数类型 1.2 阅读全文
posted @ 2016-11-25 11:20 junneyang 阅读(1773) 评论(0) 推荐(0) 编辑
摘要: 1. { 换行: Opening Brace Can't Be Placed on a Separate Line 2. 定义未使用的变量: Unused Variables 2. import 但未使用: Unused Imports 3. a := 123 简短变量定义方式只能在函数内部使用:  阅读全文
posted @ 2016-11-24 17:56 junneyang 阅读(1685) 评论(0) 推荐(0) 编辑
摘要: 在Go规范,^这个运算符在一元运算符和二元运算符中都出现了。那么他们分别是啥?在规范中说道:^ bitwise XOR integers这是按位异或。 Go语言位操作实例 阅读全文
posted @ 2016-11-24 16:52 junneyang 阅读(14729) 评论(0) 推荐(1) 编辑
摘要: 结论: 通用的UTF8编码可是Ken Thompson和Rob Pike共同发明的, 他们都是Go的作者. Go中rune对应unicode的码点, string只是UTF8编码.len("Hello, 世界")返回的是UTF8编码的字符串的字节长度;len([]rune("Hello, 世界")) 阅读全文
posted @ 2016-11-24 15:23 junneyang 阅读(3467) 评论(0) 推荐(0) 编辑
摘要: 代码: 输出: 参考资料: http://reusee.github.io/post/error-handling/ https://github.com/reusee/codes/blob/master/err/err.go https://github.com/golang/go/blob/ma 阅读全文
posted @ 2016-11-23 12:03 junneyang 阅读(1167) 评论(0) 推荐(0) 编辑
摘要: 003.GO流程与函数 003.GO流程与函数 1 概述 1 概述 1.1 Go中流程控制分三大类:条件判断,循环控制和无条件跳转 1.1 Go中流程控制分三大类:条件判断,循环控制和无条件跳转 2 流程 2 流程 2.1 if 2.1 if 2.1.1 if条件判断语句中不需要括号 2.1.1 i 阅读全文
posted @ 2016-11-23 10:00 junneyang 阅读(404) 评论(0) 推荐(0) 编辑
摘要: 最严谨的方式,Always检查error,并做相应的处理 项目结构: 代码: common.go: godep_common.go 是的,就是这么蛋疼, 所有的error不能忽略,需要检查,导致代码比较冗长。 这种办法代码非常严谨,也是Golang官方期望的方式。Golang的标准库代码也是这么写的 阅读全文
posted @ 2016-11-22 14:23 junneyang 阅读(1658) 评论(0) 推荐(0) 编辑
摘要: 吐血推荐: https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully 参考资料: https://blog.golang.org/errors-are-values https://dave.ch 阅读全文
posted @ 2016-11-22 13:22 junneyang 阅读(2159) 评论(0) 推荐(0) 编辑
摘要: 使用方法: 提交:cd ${GOPATH}/src/github.com/junneyang/xcloudgodep save -v ./...rm -rf vendor/git checkout --force git initgit pull https://github.com/junneya 阅读全文
posted @ 2016-11-21 11:59 junneyang 阅读(417) 评论(0) 推荐(0) 编辑
摘要: go处理错误的另一种方式 go处理错误常见的方式是 err := funcReturningError() if err != nil { // 处理错误 } 然而因为过于繁琐而饱受诟病。下文简述另一种处理错误的写法。 这种写法最初我是从标准库里看到的,代码在 https://github.com/ 阅读全文
posted @ 2016-11-21 10:48 junneyang 阅读(875) 评论(0) 推荐(0) 编辑
上一页 1 ··· 18 19 20 21 22 23 24 25 26 ··· 52 下一页