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"
|
2022-05-13 07:31:55 +00:00
|
|
|
"time"
|
2017-09-05 07:36:10 +00:00
|
|
|
)
|
2017-08-04 08:20:59 +00:00
|
|
|
|
|
|
|
type Slice []interface{}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
// 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)
|
|
|
|
}
|
2021-05-24 21:08:17 +00:00
|
|
|
return ObjToStr((that)[key])
|
2017-08-04 08:20:59 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 01:52:49 +00:00
|
|
|
func (that Slice) GetTime(key int, err ...*Error) *time.Time {
|
2022-05-13 07:31:55 +00:00
|
|
|
|
|
|
|
v := ObjToTime((that)[key], err...)
|
|
|
|
return v
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +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
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
// 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
|
|
|
|
|
|
|
|
}
|
2020-02-20 06:20:56 +00:00
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
// 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
|
|
|
}
|
2020-02-20 06:20:56 +00:00
|
|
|
|
2021-05-24 21:08:17 +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
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +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
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
func (that Slice) GetSlice(key int, err ...*Error) Slice {
|
|
|
|
v := ObjToSlice((that)[key], err...)
|
2017-08-04 08:20:59 +00:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
func (that Slice) GetBool(key int, err ...*Error) bool {
|
2021-05-23 21:47:56 +00:00
|
|
|
|
|
|
|
//var v Slice
|
2021-05-24 21:08:17 +00:00
|
|
|
v := ObjToBool((that)[key], err...)
|
2021-05-23 21:47:56 +00:00
|
|
|
|
|
|
|
return v
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
func (that Slice) GetMap(key int, err ...*Error) Map {
|
2017-08-04 08:20:59 +00:00
|
|
|
//var v Map
|
2021-05-24 21:08:17 +00:00
|
|
|
v := ObjToMap((that)[key], err...)
|
2017-08-04 08:20:59 +00:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
func (that Slice) Get(key int, err ...*Error) interface{} {
|
2017-08-04 08:20:59 +00:00
|
|
|
|
2021-05-24 21:08:17 +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
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
func (that Slice) Put(key int, value interface{}) {
|
|
|
|
that[key] = value
|
2017-08-04 08:20:59 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
func (that Slice) ToJsonString() string {
|
|
|
|
return ObjToStr(that)
|
2017-08-04 08:20:59 +00:00
|
|
|
}
|