iedc-go/common/slice.go

97 lines
1.8 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-09-05 07:36:10 +00:00
import (
"errors"
)
2017-08-04 08:20:59 +00:00
type Slice []interface{}
// GetString 获取string
func (that Slice) GetString(key int, err ...*Error) string {
2017-09-05 07:36:10 +00:00
if len(err) != 0 {
2017-08-04 08:20:59 +00:00
err[0].SetError(nil)
}
return ObjToStr((that)[key])
2017-08-04 08:20:59 +00:00
}
// GetInt 获取Int
func (that Slice) GetInt(key int, err ...*Error) int {
v := ObjToInt((that)[key], err...)
2017-08-04 08:20:59 +00:00
return v
}
// GetInt64 获取Int
func (that Slice) GetInt64(key int, err ...*Error) int64 {
v := ObjToInt64((that)[key], err...)
2017-08-04 08:20:59 +00:00
return v
}
// GetCeilInt64 获取向上取整Int64
func (that Slice) GetCeilInt64(key int, err ...*Error) int64 {
v := ObjToCeilInt64((that)[key], err...)
2018-01-23 18:08:25 +00:00
return v
}
// GetCeilInt 获取向上取整Int
func (that Slice) GetCeilInt(key int, err ...*Error) int {
v := ObjToCeilInt((that)[key], err...)
2018-01-23 18:08:25 +00:00
return v
2018-01-28 17:30:47 +00:00
}
// GetCeilFloat64 获取向上取整float64
func (that Slice) GetCeilFloat64(key int, err ...*Error) float64 {
v := ObjToCeilFloat64((that)[key], err...)
2018-01-28 17:30:47 +00:00
return v
2018-01-23 18:08:25 +00:00
}
// GetFloat64 获取Float64
func (that Slice) GetFloat64(key int, err ...*Error) float64 {
v := ObjToFloat64((that)[key], err...)
2017-08-04 08:20:59 +00:00
return v
}
func (that Slice) GetSlice(key int, err ...*Error) Slice {
v := ObjToSlice((that)[key], err...)
2017-08-04 08:20:59 +00:00
return v
}
func (that Slice) GetBool(key int, err ...*Error) bool {
2021-05-23 21:47:56 +00:00
//var v Slice
v := ObjToBool((that)[key], err...)
2021-05-23 21:47:56 +00:00
return v
}
func (that Slice) GetMap(key int, err ...*Error) Map {
2017-08-04 08:20:59 +00:00
//var v Map
v := ObjToMap((that)[key], err...)
2017-08-04 08:20:59 +00:00
return v
}
func (that Slice) Get(key int, err ...*Error) interface{} {
2017-08-04 08:20:59 +00:00
if key < len(that) {
return that[key]
2017-08-04 08:20:59 +00:00
}
2017-09-05 07:36:10 +00:00
e := errors.New("没有存储key及对应的数据")
if len(err) != 0 {
2017-08-04 08:20:59 +00:00
err[0].SetError(e)
}
return nil
}
func (that Slice) Put(key int, value interface{}) {
that[key] = value
2017-08-04 08:20:59 +00:00
}
func (that Slice) ToJsonString() string {
return ObjToStr(that)
2017-08-04 08:20:59 +00:00
}