iedc-go/common/obj.go

95 lines
1.6 KiB
Go
Raw Permalink Normal View History

2021-05-23 23:27:41 +00:00
package common
2017-08-04 08:20:59 +00:00
2017-08-10 10:14:56 +00:00
//对象封装方便取用
2017-08-04 08:20:59 +00:00
type Obj struct {
Data interface{}
2021-05-25 12:27:24 +00:00
Error
2021-05-23 23:27:41 +00:00
ContextBase
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
func (that *Obj) Put(data interface{}) {
that.Data = data
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
func (that *Obj) ToInt(err ...Error) int {
2017-08-04 08:20:59 +00:00
if len(err) != 0 {
2021-05-25 12:27:24 +00:00
that.Error = err[0]
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
return ObjToInt(that.Data, &that.Error)
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
func (that *Obj) ToInt64(err ...Error) int64 {
2017-08-04 08:20:59 +00:00
if len(err) != 0 {
2021-05-25 12:27:24 +00:00
that.Error = err[0]
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
return ObjToInt64(that.Data, &that.Error)
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
func (that *Obj) ToFloat64(err ...Error) float64 {
2017-08-04 08:20:59 +00:00
if len(err) != 0 {
2021-05-25 12:27:24 +00:00
that.Error = err[0]
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
return ObjToFloat64(that.Data, &that.Error)
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
// ToCeilFloat64 获取向上取整float64
func (that *Obj) ToCeilFloat64(err ...*Error) float64 {
2018-01-28 17:30:47 +00:00
if len(err) != 0 {
2021-05-25 12:27:24 +00:00
that.Error = *err[0]
2018-01-28 17:30:47 +00:00
}
2021-05-25 12:27:24 +00:00
v := ObjToCeilFloat64(that.Data, err...)
2018-01-28 17:30:47 +00:00
return v
}
2021-05-25 12:27:24 +00:00
func (that *Obj) ToStr() string {
2017-08-04 08:20:59 +00:00
2021-05-25 12:27:24 +00:00
return ObjToStr(that.Data)
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
func (that *Obj) ToMap(err ...Error) Map {
2017-08-04 08:20:59 +00:00
if len(err) != 0 {
2021-05-25 12:27:24 +00:00
that.Error = err[0]
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
return ObjToMap(that.Data, &that.Error)
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
func (that *Obj) ToSlice(err ...Error) Slice {
2017-08-04 08:20:59 +00:00
if len(err) != 0 {
2021-05-25 12:27:24 +00:00
that.Error = err[0]
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
return ObjToSlice(that.Data, &that.Error)
2017-08-04 08:20:59 +00:00
}
2021-05-25 12:27:24 +00:00
func (that *Obj) ToMapArray(err ...Error) []Map {
2018-04-09 17:16:24 +00:00
if len(err) != 0 {
2021-05-25 12:27:24 +00:00
that.Error = err[0]
2018-04-09 17:16:24 +00:00
}
2021-05-25 12:27:24 +00:00
return ObjToMapArray(that.Data, &that.Error)
2018-04-09 17:16:24 +00:00
}
2021-05-25 12:27:24 +00:00
func (that *Obj) ToObj() interface{} {
2017-08-04 08:20:59 +00:00
2021-05-25 12:27:24 +00:00
return that.Data
2017-08-04 08:20:59 +00:00
}
2018-01-23 18:08:25 +00:00
//获取向上取整Int64
2021-05-25 12:27:24 +00:00
func (that *Obj) ToCeilInt64(err ...*Error) int64 {
2018-01-28 17:30:47 +00:00
if len(err) != 0 {
2021-05-25 12:27:24 +00:00
that.Error = *err[0]
2018-01-28 17:30:47 +00:00
}
2021-05-25 12:27:24 +00:00
v := ObjToCeilInt64(that.Data, err...)
2018-01-23 18:08:25 +00:00
return v
}
2018-01-23 18:08:25 +00:00
//获取向上取整Int
2021-05-25 12:27:24 +00:00
func (that *Obj) ToCeilInt(err ...*Error) int {
2018-01-28 17:30:47 +00:00
if len(err) != 0 {
2021-05-25 12:27:24 +00:00
that.Error = *err[0]
2018-01-28 17:30:47 +00:00
}
2021-05-25 12:27:24 +00:00
v := ObjToCeilInt(that.Data, err...)
2018-01-23 18:08:25 +00:00
return v
}