iedc-go/common/obj.go

94 lines
1.6 KiB
Go
Raw 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-23 23:27:41 +00:00
ContextBase
2017-08-04 08:20:59 +00:00
}
func (this *Obj) Put(data interface{}) {
this.Data = data
}
func (this *Obj) ToInt(err ...Error) int {
if len(err) != 0 {
this.Error = err[0]
}
return ObjToInt(this.Data, &this.Error)
}
func (this *Obj) ToInt64(err ...Error) int64 {
if len(err) != 0 {
this.Error = err[0]
}
return ObjToInt64(this.Data, &this.Error)
}
func (this *Obj) ToFloat64(err ...Error) float64 {
if len(err) != 0 {
this.Error = err[0]
}
return ObjToFloat64(this.Data, &this.Error)
}
2018-01-28 17:30:47 +00:00
//获取向上取整float64
func (this *Obj) ToCeilFloat64(err ...*Error) float64 {
if len(err) != 0 {
this.Error = *err[0]
}
v := ObjToCeilFloat64(this.Data, err...)
return v
}
2017-08-04 08:20:59 +00:00
func (this *Obj) ToStr() string {
return ObjToStr(this.Data)
}
func (this *Obj) ToMap(err ...Error) Map {
if len(err) != 0 {
this.Error = err[0]
}
return ObjToMap(this.Data, &this.Error)
}
func (this *Obj) ToSlice(err ...Error) Slice {
if len(err) != 0 {
this.Error = err[0]
}
return ObjToSlice(this.Data, &this.Error)
}
func (this *Obj) ToMapArray(err ...Error) []Map {
2018-04-09 17:16:24 +00:00
if len(err) != 0 {
this.Error = err[0]
}
return ObjToMapArray(this.Data, &this.Error)
}
2017-08-04 08:20:59 +00:00
func (this *Obj) ToObj() interface{} {
return this.Data
}
2018-01-23 18:08:25 +00:00
//获取向上取整Int64
func (this *Obj) ToCeilInt64(err ...*Error) int64 {
2018-01-28 17:30:47 +00:00
if len(err) != 0 {
this.Error = *err[0]
}
2018-01-23 18:08:25 +00:00
v := ObjToCeilInt64(this.Data, err...)
return v
}
2018-01-23 18:08:25 +00:00
//获取向上取整Int
func (this *Obj) ToCeilInt(err ...*Error) int {
2018-01-28 17:30:47 +00:00
if len(err) != 0 {
this.Error = *err[0]
}
2018-01-23 18:08:25 +00:00
v := ObjToCeilInt(this.Data, err...)
return v
}