Go语言中文网 为您找到相关结果 4

代码中的缩进线

![我在2016年伦敦Golang英国会议上谈论代码缩进线](https://raw.githubusercontent.com/studygolang/gctt-images/master/line-of-sight/1_CBjBs9EzL8q1AL6XvjjpJg.png) 在近期伦敦举行的 [Golang 英国会议](https://www.youtube.com/watch?v=yeetIgNeIkc) 上,我在[地道的Go 语言窍门](https://www.youtube.com/watch?v=yeetIgNeIkc) 交流([幻灯片](http://go-talks.appspot.com/github.com/matryer/present/idiomatic-go-tri...阅读全文

博文 2018-05-10 19:58:56 polaris

GO语言 代码的嵌套——各种状态的组合

创翻译文章,转载请注明出处:服务器非业余研究-sunface 对于代码风格的争议由来已久:程序员在一段代码中到底该使用多少嵌套或者缩进结构。请先看看下面两个例子: 在第一个例子中,如果我们想在高亮代码附近进行debug,那么我们需要记住哪些呢? func (g *Gopher) WriteTo(w io.Writer) (size int64, err error) { err = binary.Write(w, binary.LittleEndian, int32(len(g.Name))) if err == nil { size += 4 var n int n, err = w.Write([]byte(g.Name)) size += int64(n) if err == nil ...阅读全文

博文 2017-10-27 21:02:28 erlib

go encoding/json 介绍

由于我一直是一名前端工程师,所以我会在前端的角度将js中的json操作和go中的操作做一个类比方便大家的理解。 将字符串转换为对象 js : JSON.parse(`{"name":"cfl"}`)go : json.Unmarshal jsonStr := `{ "name":"cfl", "age":10, "friend":[{"name":"sx", "age":10 }] }` type User struct { Name string Age int64 Friend []User } var cfl User json.Unmarshal([]byte(jsonStr), &cfl) fmt.Printf("%+v", cfl) 将对象转换为json js: JSON.str...阅读全文

博文 2019-11-17 20:32:42 曹飞龙