hotime/common/obj.go
2021-05-25 20:27:24 +08:00

95 lines
1.6 KiB
Go

package common
//对象封装方便取用
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) 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
}