hotime/common/slice.go
2021-05-25 05:08:17 +08:00

97 lines
1.8 KiB
Go

package common
import (
"errors"
)
type Slice []interface{}
// GetString 获取string
func (that Slice) GetString(key int, err ...*Error) string {
if len(err) != 0 {
err[0].SetError(nil)
}
return ObjToStr((that)[key])
}
// GetInt 获取Int
func (that Slice) GetInt(key int, err ...*Error) int {
v := ObjToInt((that)[key], err...)
return v
}
// GetInt64 获取Int
func (that Slice) GetInt64(key int, err ...*Error) int64 {
v := ObjToInt64((that)[key], err...)
return v
}
// GetCeilInt64 获取向上取整Int64
func (that Slice) GetCeilInt64(key int, err ...*Error) int64 {
v := ObjToCeilInt64((that)[key], err...)
return v
}
// GetCeilInt 获取向上取整Int
func (that Slice) GetCeilInt(key int, err ...*Error) int {
v := ObjToCeilInt((that)[key], err...)
return v
}
// GetCeilFloat64 获取向上取整float64
func (that Slice) GetCeilFloat64(key int, err ...*Error) float64 {
v := ObjToCeilFloat64((that)[key], err...)
return v
}
// GetFloat64 获取Float64
func (that Slice) GetFloat64(key int, err ...*Error) float64 {
v := ObjToFloat64((that)[key], err...)
return v
}
func (that Slice) GetSlice(key int, err ...*Error) Slice {
v := ObjToSlice((that)[key], err...)
return v
}
func (that Slice) GetBool(key int, err ...*Error) bool {
//var v Slice
v := ObjToBool((that)[key], err...)
return v
}
func (that Slice) GetMap(key int, err ...*Error) Map {
//var v Map
v := ObjToMap((that)[key], err...)
return v
}
func (that Slice) Get(key int, err ...*Error) interface{} {
if key < len(that) {
return that[key]
}
e := errors.New("没有存储key及对应的数据")
if len(err) != 0 {
err[0].SetError(e)
}
return nil
}
func (that Slice) Put(key int, value interface{}) {
that[key] = value
}
func (that Slice) ToJsonString() string {
return ObjToStr(that)
}