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

golang time 格式化 format

名词 MarshalJSON 序列化:意思是将某种结构转化为字符串格式 UnmarshalJSON 反序列化:意思是将字符串形式转化为某种结构形式 golang的时间格式 默认采用的是RFC3339,与我们常认知的格式不同,故需要转化,但是这个转化目前也有点麻烦,一种方法是重写两个接口(marshaljson跟unmarshaljson)方法。如下: package main import ( "encoding/json" "fmt" "time" ) type JSONTime struct { time.Time } func (t *JSONTime) MarshalJSON() ([]byte, error) { // 这是个奇葩,必须是这个时间点, 据说是go诞生之日, 记忆方法...阅读全文

博文 2019-07-28 13:32:41 timehorse

go方法重载

package main import "fmt" //about receiver function type Student struct { Human school string } type Employer struct { Human company string } type Human struct { name string age int phone string } //implement Human method func (h *Human) SetName(name string) { fmt.Print("human") h.name = name } func (h *Human) SetAge(age int) { h.age = age } func (...阅读全文

博文 2016-06-07 12:00:00 u010165367

go 方法的继承和重写

继承: package main import "fmt" type Human struct { name string age int phone string } type Student struct { Human //匿名字段 school string } type Employee struct { Human //匿名字段 company string } //在human上面定义了一个method func (h *Human) SayHi() { fmt.Printf("Hi, I am %s you can call me on %s\n", h.name, h.phone) } func main() { mark := Student{Human{"Mark", ...阅读全文

博文 2017-02-10 12:21:46 谢权

golang学习的点点滴滴:利用组合实现继承

package main import "fmt" type Base struct { Name string } func (b *Base) SetName(name string) { b.Name = name } func (b *Base) GetName() string { return b.Name } // 组合,实现继承 type Child struct { base Base // 这里保存的是Base类型 } // 重写GetName方法 func (c *Child) GetName() string { c.base.SetName("modify...") return c.base.GetName() } // 实现继承,但需要外部提供一个Base的实例...阅读全文

博文 2014-10-04 19:27:41 亓斌哥哥

Mongo Tools 在 2.7.7 版完全用 Go 重写了

Mongo 2.7.x 还不是稳定版本,在这个版本中,tools 工具采用 Go 重写了。 主要工具有: - **bsondump** display BSON files in a human-readable format - **mongoimport** Convert data from JSON or CSV and insert them into a collection - **mongoexport** Write an existing collection to CSV or JSON format - **mongodump/mongorestore** Dump MongoDB backups to disk in .BSON format, o...阅读全文

golang 继承与方法重写