|
|
@ -24,50 +24,73 @@ func (data Data) Get(key string) (interface{}, error) {
|
|
|
|
return value, nil
|
|
|
|
return value, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetSlice 取得切片
|
|
|
|
// GetString 取得字串
|
|
|
|
func (data Data) GetSlice(key string) (res Slice, err error) {
|
|
|
|
func (data Data) GetString(key string) (string, error) {
|
|
|
|
value, err := data.Get(key)
|
|
|
|
value, err := data.Get(key)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch value := value.(type) {
|
|
|
|
switch value := value.(type) {
|
|
|
|
case []interface{}:
|
|
|
|
case []byte:
|
|
|
|
return value, nil
|
|
|
|
return string(value), nil
|
|
|
|
case Slice:
|
|
|
|
case string:
|
|
|
|
return value, nil
|
|
|
|
return value, nil
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "", ErrFormat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetSlice 強制取得切片
|
|
|
|
// MustGetString 強制取得字串
|
|
|
|
func (data Data) MustGetSlice(key string) Slice {
|
|
|
|
func (data Data) MustGetString(key string) string {
|
|
|
|
values, _ := data.GetSlice(key)
|
|
|
|
value, _ := data.GetString(key)
|
|
|
|
return values
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetString 取得字串
|
|
|
|
// GetBytes 取得字串
|
|
|
|
func (data Data) GetString(key string) (string, error) {
|
|
|
|
func (data Data) GetBytes(key string) ([]byte, error) {
|
|
|
|
value, err := data.Get(key)
|
|
|
|
value, err := data.Get(key)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch value := value.(type) {
|
|
|
|
switch value := value.(type) {
|
|
|
|
case []byte:
|
|
|
|
case []byte:
|
|
|
|
return string(value), nil
|
|
|
|
return value, nil
|
|
|
|
case string:
|
|
|
|
case string:
|
|
|
|
|
|
|
|
return []byte(value), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetBytes 強制取得字串
|
|
|
|
|
|
|
|
func (data Data) MustGetBytes(key string) []byte {
|
|
|
|
|
|
|
|
value, _ := data.GetBytes(key)
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetSlice 取得切片
|
|
|
|
|
|
|
|
func (data Data) GetSlice(key string) (res Slice, err error) {
|
|
|
|
|
|
|
|
value, err := data.Get(key)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch value := value.(type) {
|
|
|
|
|
|
|
|
case []interface{}:
|
|
|
|
|
|
|
|
return Slice(value), nil
|
|
|
|
|
|
|
|
case Slice:
|
|
|
|
return value, nil
|
|
|
|
return value, nil
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return "", ErrFormat
|
|
|
|
return nil, ErrFormat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetString 強制取得字串
|
|
|
|
// MustGetSlice 強制取得切片
|
|
|
|
func (data Data) MustGetString(key string) string {
|
|
|
|
func (data Data) MustGetSlice(key string) Slice {
|
|
|
|
value, _ := data.GetString(key)
|
|
|
|
values, _ := data.GetSlice(key)
|
|
|
|
return value
|
|
|
|
return values
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetStringSlice 取得字串切片
|
|
|
|
// GetStringSlice 取得字串切片
|
|
|
@ -95,27 +118,29 @@ func (data Data) MustGetStringSlice(key string) []string {
|
|
|
|
return values
|
|
|
|
return values
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetBytes 取得字串
|
|
|
|
// GetIntSlice 取得整數切片
|
|
|
|
func (data Data) GetBytes(key string) ([]byte, error) {
|
|
|
|
func (data Data) GetIntSlice(key string) (res []int, err error) {
|
|
|
|
value, err := data.Get(key)
|
|
|
|
values, err := data.GetSlice(key)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch value := value.(type) {
|
|
|
|
for _, v := range values {
|
|
|
|
case []byte:
|
|
|
|
switch v := v.(type) {
|
|
|
|
return value, nil
|
|
|
|
case float64:
|
|
|
|
case string:
|
|
|
|
res = append(res, int(v))
|
|
|
|
return []byte(value), nil
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return nil, ErrFormat
|
|
|
|
return nil, ErrFormat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetBytes 強制取得字串
|
|
|
|
// MustGetIntSlice 強制取得整數切片
|
|
|
|
func (data Data) MustGetBytes(key string) []byte {
|
|
|
|
func (data Data) MustGetIntSlice(key string) []int {
|
|
|
|
value, _ := data.GetBytes(key)
|
|
|
|
values, _ := data.GetIntSlice(key)
|
|
|
|
return value
|
|
|
|
return values
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetData 取得資料
|
|
|
|
// GetData 取得資料
|
|
|
@ -148,17 +173,17 @@ func (data Data) GetDataSlice(key string) ([]Data, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var list []Data
|
|
|
|
var vals []Data
|
|
|
|
for _, v := range values {
|
|
|
|
for _, v := range values {
|
|
|
|
switch v := v.(type) {
|
|
|
|
switch v := v.(type) {
|
|
|
|
case Data:
|
|
|
|
case map[string]interface{}:
|
|
|
|
list = append(list, v)
|
|
|
|
vals = append(vals, Data(v))
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return nil, ErrFormat
|
|
|
|
return nil, ErrFormat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return list, nil
|
|
|
|
return vals, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetDataSlice 強制取得資料切片
|
|
|
|
// MustGetDataSlice 強制取得資料切片
|
|
|
@ -179,9 +204,9 @@ func (data Data) GetFloat64(key string) (float64, error) {
|
|
|
|
return float64(value), nil
|
|
|
|
return float64(value), nil
|
|
|
|
case float64:
|
|
|
|
case float64:
|
|
|
|
return value, nil
|
|
|
|
return value, nil
|
|
|
|
default:
|
|
|
|
|
|
|
|
return 0, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0, ErrFormat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetFloat64 強制取得64位元浮點數
|
|
|
|
// MustGetFloat64 強制取得64位元浮點數
|
|
|
@ -190,53 +215,6 @@ func (data Data) MustGetFloat64(key string) float64 {
|
|
|
|
return value
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetFloat64Slice 取得64位元浮點數切片
|
|
|
|
|
|
|
|
func (data Data) GetFloat64Slice(key string) (res []float64, err error) {
|
|
|
|
|
|
|
|
values, err := data.GetSlice(key)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range values {
|
|
|
|
|
|
|
|
switch v := v.(type) {
|
|
|
|
|
|
|
|
case int:
|
|
|
|
|
|
|
|
res = append(res, float64(v))
|
|
|
|
|
|
|
|
case uint:
|
|
|
|
|
|
|
|
res = append(res, float64(v))
|
|
|
|
|
|
|
|
case int8:
|
|
|
|
|
|
|
|
res = append(res, float64(v))
|
|
|
|
|
|
|
|
case uint8:
|
|
|
|
|
|
|
|
res = append(res, float64(v))
|
|
|
|
|
|
|
|
case int16:
|
|
|
|
|
|
|
|
res = append(res, float64(v))
|
|
|
|
|
|
|
|
case uint16:
|
|
|
|
|
|
|
|
res = append(res, float64(v))
|
|
|
|
|
|
|
|
case int32:
|
|
|
|
|
|
|
|
res = append(res, float64(v))
|
|
|
|
|
|
|
|
case uint32:
|
|
|
|
|
|
|
|
res = append(res, float64(v))
|
|
|
|
|
|
|
|
case int64:
|
|
|
|
|
|
|
|
res = append(res, float64(v))
|
|
|
|
|
|
|
|
case uint64:
|
|
|
|
|
|
|
|
res = append(res, float64(v))
|
|
|
|
|
|
|
|
case float32:
|
|
|
|
|
|
|
|
res = append(res, float64(v))
|
|
|
|
|
|
|
|
case float64:
|
|
|
|
|
|
|
|
res = append(res, v)
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetFloat64Slice 強制取得64位元浮點數切片
|
|
|
|
|
|
|
|
func (data Data) MustGetFloat64Slice(key string) []float64 {
|
|
|
|
|
|
|
|
values, _ := data.GetFloat64Slice(key)
|
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetInt64 取得64位元整數
|
|
|
|
// GetInt64 取得64位元整數
|
|
|
|
func (data Data) GetInt64(key string) (int64, error) {
|
|
|
|
func (data Data) GetInt64(key string) (int64, error) {
|
|
|
|
value, err := data.Get(key)
|
|
|
|
value, err := data.Get(key)
|
|
|
@ -249,25 +227,30 @@ func (data Data) GetInt64(key string) (int64, error) {
|
|
|
|
return int64(value), nil
|
|
|
|
return int64(value), nil
|
|
|
|
case uint:
|
|
|
|
case uint:
|
|
|
|
return int64(value), nil
|
|
|
|
return int64(value), nil
|
|
|
|
|
|
|
|
|
|
|
|
case int8:
|
|
|
|
case int8:
|
|
|
|
return int64(value), nil
|
|
|
|
return int64(value), nil
|
|
|
|
case uint8:
|
|
|
|
case uint8:
|
|
|
|
return int64(value), nil
|
|
|
|
return int64(value), nil
|
|
|
|
|
|
|
|
|
|
|
|
case int16:
|
|
|
|
case int16:
|
|
|
|
return int64(value), nil
|
|
|
|
return int64(value), nil
|
|
|
|
case uint16:
|
|
|
|
case uint16:
|
|
|
|
return int64(value), nil
|
|
|
|
return int64(value), nil
|
|
|
|
|
|
|
|
|
|
|
|
case int32:
|
|
|
|
case int32:
|
|
|
|
return int64(value), nil
|
|
|
|
return int64(value), nil
|
|
|
|
case uint32:
|
|
|
|
case uint32:
|
|
|
|
return int64(value), nil
|
|
|
|
return int64(value), nil
|
|
|
|
|
|
|
|
|
|
|
|
case int64:
|
|
|
|
case int64:
|
|
|
|
return value, nil
|
|
|
|
return value, nil
|
|
|
|
|
|
|
|
|
|
|
|
case float64:
|
|
|
|
case float64:
|
|
|
|
return int64(value), nil
|
|
|
|
return int64(value), nil
|
|
|
|
default:
|
|
|
|
|
|
|
|
return 0, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0, ErrFormat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetInt64 強制取得64位元整數
|
|
|
|
// MustGetInt64 強制取得64位元整數
|
|
|
@ -276,53 +259,6 @@ func (data Data) MustGetInt64(key string) int64 {
|
|
|
|
return value
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetInt64Slice 取得64位元整數切片
|
|
|
|
|
|
|
|
func (data Data) GetInt64Slice(key string) (res []int64, err error) {
|
|
|
|
|
|
|
|
values, err := data.GetSlice(key)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range values {
|
|
|
|
|
|
|
|
switch v := v.(type) {
|
|
|
|
|
|
|
|
case int:
|
|
|
|
|
|
|
|
res = append(res, int64(v))
|
|
|
|
|
|
|
|
case uint:
|
|
|
|
|
|
|
|
res = append(res, int64(v))
|
|
|
|
|
|
|
|
case int8:
|
|
|
|
|
|
|
|
res = append(res, int64(v))
|
|
|
|
|
|
|
|
case uint8:
|
|
|
|
|
|
|
|
res = append(res, int64(v))
|
|
|
|
|
|
|
|
case int16:
|
|
|
|
|
|
|
|
res = append(res, int64(v))
|
|
|
|
|
|
|
|
case uint16:
|
|
|
|
|
|
|
|
res = append(res, int64(v))
|
|
|
|
|
|
|
|
case int32:
|
|
|
|
|
|
|
|
res = append(res, int64(v))
|
|
|
|
|
|
|
|
case uint32:
|
|
|
|
|
|
|
|
res = append(res, int64(v))
|
|
|
|
|
|
|
|
case int64:
|
|
|
|
|
|
|
|
res = append(res, v)
|
|
|
|
|
|
|
|
case uint64:
|
|
|
|
|
|
|
|
res = append(res, int64(v))
|
|
|
|
|
|
|
|
case float32:
|
|
|
|
|
|
|
|
res = append(res, int64(v))
|
|
|
|
|
|
|
|
case float64:
|
|
|
|
|
|
|
|
res = append(res, int64(v))
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetInt64Slice 強制取得64位元整數切片
|
|
|
|
|
|
|
|
func (data Data) MustGetInt64Slice(key string) []int64 {
|
|
|
|
|
|
|
|
values, _ := data.GetInt64Slice(key)
|
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetUint64 取得64位元正整數
|
|
|
|
// GetUint64 取得64位元正整數
|
|
|
|
func (data Data) GetUint64(key string) (uint64, error) {
|
|
|
|
func (data Data) GetUint64(key string) (uint64, error) {
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
@ -343,53 +279,6 @@ func (data Data) MustGetUint64(key string) uint64 {
|
|
|
|
return value
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetUint64Slice 取得64位元正整數切片
|
|
|
|
|
|
|
|
func (data Data) GetUint64Slice(key string) (res []uint64, err error) {
|
|
|
|
|
|
|
|
values, err := data.GetSlice(key)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range values {
|
|
|
|
|
|
|
|
switch v := v.(type) {
|
|
|
|
|
|
|
|
case int:
|
|
|
|
|
|
|
|
res = append(res, uint64(v))
|
|
|
|
|
|
|
|
case uint:
|
|
|
|
|
|
|
|
res = append(res, uint64(v))
|
|
|
|
|
|
|
|
case int8:
|
|
|
|
|
|
|
|
res = append(res, uint64(v))
|
|
|
|
|
|
|
|
case uint8:
|
|
|
|
|
|
|
|
res = append(res, uint64(v))
|
|
|
|
|
|
|
|
case int16:
|
|
|
|
|
|
|
|
res = append(res, uint64(v))
|
|
|
|
|
|
|
|
case uint16:
|
|
|
|
|
|
|
|
res = append(res, uint64(v))
|
|
|
|
|
|
|
|
case int32:
|
|
|
|
|
|
|
|
res = append(res, uint64(v))
|
|
|
|
|
|
|
|
case uint32:
|
|
|
|
|
|
|
|
res = append(res, uint64(v))
|
|
|
|
|
|
|
|
case int64:
|
|
|
|
|
|
|
|
res = append(res, uint64(v))
|
|
|
|
|
|
|
|
case uint64:
|
|
|
|
|
|
|
|
res = append(res, v)
|
|
|
|
|
|
|
|
case float32:
|
|
|
|
|
|
|
|
res = append(res, uint64(v))
|
|
|
|
|
|
|
|
case float64:
|
|
|
|
|
|
|
|
res = append(res, uint64(v))
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetUint64Slice 強制取得64位元正整數切片
|
|
|
|
|
|
|
|
func (data Data) MustGetUint64Slice(key string) []uint64 {
|
|
|
|
|
|
|
|
values, _ := data.GetUint64Slice(key)
|
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetInt 取得整數
|
|
|
|
// GetInt 取得整數
|
|
|
|
func (data Data) GetInt(key string) (int, error) {
|
|
|
|
func (data Data) GetInt(key string) (int, error) {
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
@ -406,53 +295,6 @@ func (data Data) MustGetInt(key string) int {
|
|
|
|
return value
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetIntSlice 取得整數切片
|
|
|
|
|
|
|
|
func (data Data) GetIntSlice(key string) (res []int, err error) {
|
|
|
|
|
|
|
|
values, err := data.GetSlice(key)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range values {
|
|
|
|
|
|
|
|
switch v := v.(type) {
|
|
|
|
|
|
|
|
case int:
|
|
|
|
|
|
|
|
res = append(res, v)
|
|
|
|
|
|
|
|
case uint:
|
|
|
|
|
|
|
|
res = append(res, int(v))
|
|
|
|
|
|
|
|
case int8:
|
|
|
|
|
|
|
|
res = append(res, int(v))
|
|
|
|
|
|
|
|
case uint8:
|
|
|
|
|
|
|
|
res = append(res, int(v))
|
|
|
|
|
|
|
|
case int16:
|
|
|
|
|
|
|
|
res = append(res, int(v))
|
|
|
|
|
|
|
|
case uint16:
|
|
|
|
|
|
|
|
res = append(res, int(v))
|
|
|
|
|
|
|
|
case int32:
|
|
|
|
|
|
|
|
res = append(res, int(v))
|
|
|
|
|
|
|
|
case uint32:
|
|
|
|
|
|
|
|
res = append(res, int(v))
|
|
|
|
|
|
|
|
case int64:
|
|
|
|
|
|
|
|
res = append(res, int(v))
|
|
|
|
|
|
|
|
case uint64:
|
|
|
|
|
|
|
|
res = append(res, int(v))
|
|
|
|
|
|
|
|
case float32:
|
|
|
|
|
|
|
|
res = append(res, int(v))
|
|
|
|
|
|
|
|
case float64:
|
|
|
|
|
|
|
|
res = append(res, int(v))
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetIntSlice 強制取得整數切片
|
|
|
|
|
|
|
|
func (data Data) MustGetIntSlice(key string) []int {
|
|
|
|
|
|
|
|
values, _ := data.GetIntSlice(key)
|
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetUint 取得正整數
|
|
|
|
// GetUint 取得正整數
|
|
|
|
func (data Data) GetUint(key string) (uint, error) {
|
|
|
|
func (data Data) GetUint(key string) (uint, error) {
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
@ -473,53 +315,6 @@ func (data Data) MustGetUint(key string) uint {
|
|
|
|
return value
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetUintSlice 取得正整數切片
|
|
|
|
|
|
|
|
func (data Data) GetUintSlice(key string) (res []uint, err error) {
|
|
|
|
|
|
|
|
values, err := data.GetSlice(key)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range values {
|
|
|
|
|
|
|
|
switch v := v.(type) {
|
|
|
|
|
|
|
|
case int:
|
|
|
|
|
|
|
|
res = append(res, uint(v))
|
|
|
|
|
|
|
|
case uint:
|
|
|
|
|
|
|
|
res = append(res, v)
|
|
|
|
|
|
|
|
case int8:
|
|
|
|
|
|
|
|
res = append(res, uint(v))
|
|
|
|
|
|
|
|
case uint8:
|
|
|
|
|
|
|
|
res = append(res, uint(v))
|
|
|
|
|
|
|
|
case int16:
|
|
|
|
|
|
|
|
res = append(res, uint(v))
|
|
|
|
|
|
|
|
case uint16:
|
|
|
|
|
|
|
|
res = append(res, uint(v))
|
|
|
|
|
|
|
|
case int32:
|
|
|
|
|
|
|
|
res = append(res, uint(v))
|
|
|
|
|
|
|
|
case uint32:
|
|
|
|
|
|
|
|
res = append(res, uint(v))
|
|
|
|
|
|
|
|
case int64:
|
|
|
|
|
|
|
|
res = append(res, uint(v))
|
|
|
|
|
|
|
|
case uint64:
|
|
|
|
|
|
|
|
res = append(res, uint(v))
|
|
|
|
|
|
|
|
case float32:
|
|
|
|
|
|
|
|
res = append(res, uint(v))
|
|
|
|
|
|
|
|
case float64:
|
|
|
|
|
|
|
|
res = append(res, uint(v))
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetUintSlice 強制取得正整數切片
|
|
|
|
|
|
|
|
func (data Data) MustGetUintSlice(key string) []uint {
|
|
|
|
|
|
|
|
values, _ := data.GetUintSlice(key)
|
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetInt16 取得16位元整數
|
|
|
|
// GetInt16 取得16位元整數
|
|
|
|
func (data Data) GetInt16(key string) (int16, error) {
|
|
|
|
func (data Data) GetInt16(key string) (int16, error) {
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
@ -536,53 +331,6 @@ func (data Data) MustGetInt16(key string) uint16 {
|
|
|
|
return value
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetInt16Slice 取得16位元整數切片
|
|
|
|
|
|
|
|
func (data Data) GetInt16Slice(key string) (res []int16, err error) {
|
|
|
|
|
|
|
|
values, err := data.GetSlice(key)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range values {
|
|
|
|
|
|
|
|
switch v := v.(type) {
|
|
|
|
|
|
|
|
case int:
|
|
|
|
|
|
|
|
res = append(res, int16(v))
|
|
|
|
|
|
|
|
case uint:
|
|
|
|
|
|
|
|
res = append(res, int16(v))
|
|
|
|
|
|
|
|
case int8:
|
|
|
|
|
|
|
|
res = append(res, int16(v))
|
|
|
|
|
|
|
|
case uint8:
|
|
|
|
|
|
|
|
res = append(res, int16(v))
|
|
|
|
|
|
|
|
case int16:
|
|
|
|
|
|
|
|
res = append(res, v)
|
|
|
|
|
|
|
|
case uint16:
|
|
|
|
|
|
|
|
res = append(res, int16(v))
|
|
|
|
|
|
|
|
case int32:
|
|
|
|
|
|
|
|
res = append(res, int16(v))
|
|
|
|
|
|
|
|
case uint32:
|
|
|
|
|
|
|
|
res = append(res, int16(v))
|
|
|
|
|
|
|
|
case int64:
|
|
|
|
|
|
|
|
res = append(res, int16(v))
|
|
|
|
|
|
|
|
case uint64:
|
|
|
|
|
|
|
|
res = append(res, int16(v))
|
|
|
|
|
|
|
|
case float32:
|
|
|
|
|
|
|
|
res = append(res, int16(v))
|
|
|
|
|
|
|
|
case float64:
|
|
|
|
|
|
|
|
res = append(res, int16(v))
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetInt16Slice 強制取得16位元整數切片
|
|
|
|
|
|
|
|
func (data Data) MustGetInt16Slice(key string) []int16 {
|
|
|
|
|
|
|
|
values, _ := data.GetInt16Slice(key)
|
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetUint16 取得16位元正整數
|
|
|
|
// GetUint16 取得16位元正整數
|
|
|
|
func (data Data) GetUint16(key string) (uint16, error) {
|
|
|
|
func (data Data) GetUint16(key string) (uint16, error) {
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
@ -603,53 +351,6 @@ func (data Data) MustGetUint16(key string) uint16 {
|
|
|
|
return value
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetUint16Slice 取得16位元正整數切片
|
|
|
|
|
|
|
|
func (data Data) GetUint16Slice(key string) (res []uint16, err error) {
|
|
|
|
|
|
|
|
values, err := data.GetSlice(key)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range values {
|
|
|
|
|
|
|
|
switch v := v.(type) {
|
|
|
|
|
|
|
|
case int:
|
|
|
|
|
|
|
|
res = append(res, uint16(v))
|
|
|
|
|
|
|
|
case uint:
|
|
|
|
|
|
|
|
res = append(res, uint16(v))
|
|
|
|
|
|
|
|
case int8:
|
|
|
|
|
|
|
|
res = append(res, uint16(v))
|
|
|
|
|
|
|
|
case uint8:
|
|
|
|
|
|
|
|
res = append(res, uint16(v))
|
|
|
|
|
|
|
|
case int16:
|
|
|
|
|
|
|
|
res = append(res, uint16(v))
|
|
|
|
|
|
|
|
case uint16:
|
|
|
|
|
|
|
|
res = append(res, v)
|
|
|
|
|
|
|
|
case int32:
|
|
|
|
|
|
|
|
res = append(res, uint16(v))
|
|
|
|
|
|
|
|
case uint32:
|
|
|
|
|
|
|
|
res = append(res, uint16(v))
|
|
|
|
|
|
|
|
case int64:
|
|
|
|
|
|
|
|
res = append(res, uint16(v))
|
|
|
|
|
|
|
|
case uint64:
|
|
|
|
|
|
|
|
res = append(res, uint16(v))
|
|
|
|
|
|
|
|
case float32:
|
|
|
|
|
|
|
|
res = append(res, uint16(v))
|
|
|
|
|
|
|
|
case float64:
|
|
|
|
|
|
|
|
res = append(res, uint16(v))
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetUint16Slice 強制取得16位元正整數切片
|
|
|
|
|
|
|
|
func (data Data) MustGetUint16Slice(key string) []uint16 {
|
|
|
|
|
|
|
|
values, _ := data.GetUint16Slice(key)
|
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetInt8 取得8位元整數
|
|
|
|
// GetInt8 取得8位元整數
|
|
|
|
func (data Data) GetInt8(key string) (int8, error) {
|
|
|
|
func (data Data) GetInt8(key string) (int8, error) {
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
@ -666,53 +367,6 @@ func (data Data) MustGetInt8(key string) int8 {
|
|
|
|
return value
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetInt8Slice 取得8位元整數切片
|
|
|
|
|
|
|
|
func (data Data) GetInt8Slice(key string) (res []int8, err error) {
|
|
|
|
|
|
|
|
values, err := data.GetSlice(key)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range values {
|
|
|
|
|
|
|
|
switch v := v.(type) {
|
|
|
|
|
|
|
|
case int:
|
|
|
|
|
|
|
|
res = append(res, int8(v))
|
|
|
|
|
|
|
|
case uint:
|
|
|
|
|
|
|
|
res = append(res, int8(v))
|
|
|
|
|
|
|
|
case int8:
|
|
|
|
|
|
|
|
res = append(res, v)
|
|
|
|
|
|
|
|
case uint8:
|
|
|
|
|
|
|
|
res = append(res, int8(v))
|
|
|
|
|
|
|
|
case int16:
|
|
|
|
|
|
|
|
res = append(res, int8(v))
|
|
|
|
|
|
|
|
case uint16:
|
|
|
|
|
|
|
|
res = append(res, int8(v))
|
|
|
|
|
|
|
|
case int32:
|
|
|
|
|
|
|
|
res = append(res, int8(v))
|
|
|
|
|
|
|
|
case uint32:
|
|
|
|
|
|
|
|
res = append(res, int8(v))
|
|
|
|
|
|
|
|
case int64:
|
|
|
|
|
|
|
|
res = append(res, int8(v))
|
|
|
|
|
|
|
|
case uint64:
|
|
|
|
|
|
|
|
res = append(res, int8(v))
|
|
|
|
|
|
|
|
case float32:
|
|
|
|
|
|
|
|
res = append(res, int8(v))
|
|
|
|
|
|
|
|
case float64:
|
|
|
|
|
|
|
|
res = append(res, int8(v))
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetInt8Slice 強制取得8位元整數切片
|
|
|
|
|
|
|
|
func (data Data) MustGetInt8Slice(key string) []int8 {
|
|
|
|
|
|
|
|
values, _ := data.GetInt8Slice(key)
|
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetUint8 取得8位元正整數
|
|
|
|
// GetUint8 取得8位元正整數
|
|
|
|
func (data Data) GetUint8(key string) (uint8, error) {
|
|
|
|
func (data Data) GetUint8(key string) (uint8, error) {
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
|
value, err := data.GetInt64(key)
|
|
|
@ -733,53 +387,6 @@ func (data Data) MustGetUint8(key string) uint8 {
|
|
|
|
return value
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetUint8Slice 取得8位元正整數切片
|
|
|
|
|
|
|
|
func (data Data) GetUint8Slice(key string) (res []uint8, err error) {
|
|
|
|
|
|
|
|
values, err := data.GetSlice(key)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range values {
|
|
|
|
|
|
|
|
switch v := v.(type) {
|
|
|
|
|
|
|
|
case int:
|
|
|
|
|
|
|
|
res = append(res, uint8(v))
|
|
|
|
|
|
|
|
case uint:
|
|
|
|
|
|
|
|
res = append(res, uint8(v))
|
|
|
|
|
|
|
|
case int8:
|
|
|
|
|
|
|
|
res = append(res, uint8(v))
|
|
|
|
|
|
|
|
case uint8:
|
|
|
|
|
|
|
|
res = append(res, v)
|
|
|
|
|
|
|
|
case int16:
|
|
|
|
|
|
|
|
res = append(res, uint8(v))
|
|
|
|
|
|
|
|
case uint16:
|
|
|
|
|
|
|
|
res = append(res, uint8(v))
|
|
|
|
|
|
|
|
case int32:
|
|
|
|
|
|
|
|
res = append(res, uint8(v))
|
|
|
|
|
|
|
|
case uint32:
|
|
|
|
|
|
|
|
res = append(res, uint8(v))
|
|
|
|
|
|
|
|
case int64:
|
|
|
|
|
|
|
|
res = append(res, uint8(v))
|
|
|
|
|
|
|
|
case uint64:
|
|
|
|
|
|
|
|
res = append(res, uint8(v))
|
|
|
|
|
|
|
|
case float32:
|
|
|
|
|
|
|
|
res = append(res, uint8(v))
|
|
|
|
|
|
|
|
case float64:
|
|
|
|
|
|
|
|
res = append(res, uint8(v))
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, ErrFormat
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetUint8Slice 強制取得8位元正整數切片
|
|
|
|
|
|
|
|
func (data Data) MustGetUint8Slice(key string) []uint8 {
|
|
|
|
|
|
|
|
values, _ := data.GetUint8Slice(key)
|
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetBool 取得布林值
|
|
|
|
// GetBool 取得布林值
|
|
|
|
func (data Data) GetBool(key string) (bool, error) {
|
|
|
|
func (data Data) GetBool(key string) (bool, error) {
|
|
|
|
value, err := data.Get(key)
|
|
|
|
value, err := data.Get(key)
|
|
|
@ -789,11 +396,7 @@ func (data Data) GetBool(key string) (bool, error) {
|
|
|
|
|
|
|
|
|
|
|
|
switch value := value.(type) {
|
|
|
|
switch value := value.(type) {
|
|
|
|
case uint8:
|
|
|
|
case uint8:
|
|
|
|
return value > 0, nil
|
|
|
|
return value == 1, nil
|
|
|
|
case int64:
|
|
|
|
|
|
|
|
return value > 0, nil
|
|
|
|
|
|
|
|
case float64:
|
|
|
|
|
|
|
|
return value > 0, nil
|
|
|
|
|
|
|
|
case bool:
|
|
|
|
case bool:
|
|
|
|
return value, nil
|
|
|
|
return value, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -819,13 +422,14 @@ func (data Data) GetTimestamp(key string) (Timestamp, error) {
|
|
|
|
return Timestamp(value), nil
|
|
|
|
return Timestamp(value), nil
|
|
|
|
case uint:
|
|
|
|
case uint:
|
|
|
|
return Timestamp(value), nil
|
|
|
|
return Timestamp(value), nil
|
|
|
|
|
|
|
|
case int32:
|
|
|
|
|
|
|
|
return Timestamp(value), nil
|
|
|
|
|
|
|
|
case uint32:
|
|
|
|
|
|
|
|
return Timestamp(value), nil
|
|
|
|
case int64:
|
|
|
|
case int64:
|
|
|
|
return Timestamp(value), nil
|
|
|
|
return Timestamp(value), nil
|
|
|
|
case uint64:
|
|
|
|
case uint64:
|
|
|
|
return Timestamp(value), nil
|
|
|
|
return Timestamp(value), nil
|
|
|
|
case float64:
|
|
|
|
|
|
|
|
return Timestamp(value), nil
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case Timestamp:
|
|
|
|
case Timestamp:
|
|
|
|
return value, nil
|
|
|
|
return value, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -855,7 +459,7 @@ func (data Data) MustJSON() []byte {
|
|
|
|
return bs
|
|
|
|
return bs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetPage 取得頁數
|
|
|
|
// Get 取得資料
|
|
|
|
func (data Data) GetPage(key string) (*Page, error) {
|
|
|
|
func (data Data) GetPage(key string) (*Page, error) {
|
|
|
|
value, err := data.Get(key)
|
|
|
|
value, err := data.Get(key)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -870,7 +474,7 @@ func (data Data) GetPage(key string) (*Page, error) {
|
|
|
|
return nil, ErrFormat
|
|
|
|
return nil, ErrFormat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MustGetPage 強制取得頁數
|
|
|
|
// Get 取得資料
|
|
|
|
func (data Data) MustGetPage(key string) *Page {
|
|
|
|
func (data Data) MustGetPage(key string) *Page {
|
|
|
|
value, _ := data.GetPage(key)
|
|
|
|
value, _ := data.GetPage(key)
|
|
|
|
|
|
|
|
|
|
|
|