hotime/slice.go
2017-09-19 07:39:35 +00:00

74 lines
1.3 KiB
Go

package hotime
import (
"encoding/json"
"errors"
)
type Slice []interface{}
//获取string
func (this Slice) GetString(key int, err ...*Error) string {
if len(err) != 0 {
err[0].SetError(nil)
}
return ObjToStr((this)[key])
}
//获取Int
func (this Slice) GetInt(key int, err ...*Error) int {
v := ObjToInt((this)[key], err...)
return v
}
//获取Int
func (this Slice) GetInt64(key int, err ...*Error) int64 {
v := ObjToInt64((this)[key], err...)
return v
}
//获取Float64
func (this Slice) GetFloat64(key int, err ...*Error) float64 {
v := ObjToFloat64((this)[key], err...)
return v
}
func (this Slice) GetSlice(key int, err ...*Error) Slice {
v := ObjToSlice((this)[key], err...)
return v
}
func (this Slice) GetMap(key int, err ...*Error) Map {
//var v Map
v := ObjToMap((this)[key], err...)
return v
}
func (this Slice) Get(key int, err ...*Error) interface{} {
if key < len(this) {
return this[key]
}
e := errors.New("没有存储key及对应的数据")
if len(err) != 0 {
err[0].SetError(e)
}
return nil
}
func (this Slice) Put(key int, value interface{}) {
this[key] = value
}
func (this Slice) GetJsonString() string {
return ObjToStr(this)
}
func (this Slice) JsonToSlice(jsonStr string) {
json.Unmarshal([]byte(jsonStr), &this)
}