package common import "time" // 对象封装方便取用 type Obj struct { Data interface{} Error ContextBase } func (that *Obj) Put(data interface{}) { that.Data = data } func (that *Obj) ToInt(err ...Error) int { if len(err) != 0 { that.Error = err[0] } return ObjToInt(that.Data, &that.Error) } func (that *Obj) ToTime(err ...Error) *time.Time { if len(err) != 0 { that.Error = err[0] } return ObjToTime(that.Data, &that.Error) } func (that *Obj) ToInt64(err ...Error) int64 { if len(err) != 0 { that.Error = err[0] } return ObjToInt64(that.Data, &that.Error) } func (that *Obj) ToFloat64(err ...Error) float64 { if len(err) != 0 { that.Error = err[0] } return ObjToFloat64(that.Data, &that.Error) } // ToCeilFloat64 获取向上取整float64 func (that *Obj) ToCeilFloat64(err ...*Error) float64 { if len(err) != 0 { that.Error = *err[0] } v := ObjToCeilFloat64(that.Data, err...) return v } func (that *Obj) ToStr() string { return ObjToStr(that.Data) } func (that *Obj) ToMap(err ...Error) Map { if len(err) != 0 { that.Error = err[0] } return ObjToMap(that.Data, &that.Error) } func (that *Obj) ToSlice(err ...Error) Slice { if len(err) != 0 { that.Error = err[0] } return ObjToSlice(that.Data, &that.Error) } func (that *Obj) ToMapArray(err ...Error) []Map { if len(err) != 0 { that.Error = err[0] } return ObjToMapArray(that.Data, &that.Error) } func (that *Obj) ToObj() interface{} { return that.Data } // 获取向上取整Int64 func (that *Obj) ToCeilInt64(err ...*Error) int64 { if len(err) != 0 { that.Error = *err[0] } v := ObjToCeilInt64(that.Data, err...) return v } // 获取向上取整Int func (that *Obj) ToCeilInt(err ...*Error) int { if len(err) != 0 { that.Error = *err[0] } v := ObjToCeilInt(that.Data, err...) return v }