Add must get func

tags/v1.0.6 v1.0.6
Stanly 4 years ago
parent 2b62384dd9
commit 2a78c5e845

@ -34,6 +34,11 @@ func (data Data) GetString(key string) (string, error) {
return "", ErrFormat return "", ErrFormat
} }
func (data Data) MustGetString(key string) string {
value, _ := data.GetString(key)
return value
}
func (data Data) GetSlice(key string) (res []interface{}, err error) { func (data Data) GetSlice(key string) (res []interface{}, err error) {
value, err := data.Get(key) value, err := data.Get(key)
if err != nil { if err != nil {
@ -48,6 +53,11 @@ func (data Data) GetSlice(key string) (res []interface{}, err error) {
} }
} }
func (data Data) MustGetSlice(key string) []interface{} {
values, _ := data.GetSlice(key)
return values
}
func (data Data) GetStringSlice(key string) (res []string, err error) { func (data Data) GetStringSlice(key string) (res []string, err error) {
values, err := data.GetSlice(key) values, err := data.GetSlice(key)
if err != nil { if err != nil {
@ -66,6 +76,11 @@ func (data Data) GetStringSlice(key string) (res []string, err error) {
return res, nil return res, nil
} }
func (data Data) MustGetStringSlice(key string) []string {
values, _ := data.GetStringSlice(key)
return values
}
func (data Data) GetIntSlice(key string) (res []int, err error) { func (data Data) GetIntSlice(key string) (res []int, err error) {
values, err := data.GetSlice(key) values, err := data.GetSlice(key)
if err != nil { if err != nil {
@ -84,6 +99,11 @@ func (data Data) GetIntSlice(key string) (res []int, err error) {
return res, nil return res, nil
} }
func (data Data) MustGetIntSlice(key string) []int {
values, _ := data.GetIntSlice(key)
return values
}
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)
if err != nil { if err != nil {
@ -104,6 +124,11 @@ func (data Data) GetInt64(key string) (int64, error) {
return 0, ErrFormat return 0, ErrFormat
} }
func (data Data) MustGetInt64(key string) int64 {
value, _ := data.GetInt64(key)
return value
}
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)
if err != nil { if err != nil {
@ -117,6 +142,11 @@ func (data Data) GetUint64(key string) (uint64, error) {
return uint64(value), nil return uint64(value), nil
} }
func (data Data) MustGetUint64(key string) uint64 {
value, _ := data.GetUint64(key)
return value
}
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)
if err != nil { if err != nil {
@ -126,6 +156,11 @@ func (data Data) GetInt(key string) (int, error) {
return int(value), nil return int(value), nil
} }
func (data Data) MustGetInt(key string) int {
value, _ := data.GetInt(key)
return value
}
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)
if err != nil { if err != nil {
@ -139,6 +174,11 @@ func (data Data) GetUint(key string) (uint, error) {
return uint(value), nil return uint(value), nil
} }
func (data Data) MustGetUint(key string) uint {
value, _ := data.GetUint(key)
return value
}
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)
if err != nil { if err != nil {
@ -161,6 +201,11 @@ func (data Data) GetUint16(key string) (uint16, error) {
return uint16(value), nil return uint16(value), nil
} }
func (data Data) MustGetUint16(key string) uint16 {
value, _ := data.GetUint16(key)
return value
}
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)
if err != nil { if err != nil {
@ -170,6 +215,11 @@ func (data Data) GetInt8(key string) (int8, error) {
return int8(value), nil return int8(value), nil
} }
func (data Data) MustGetInt8(key string) int8 {
value, _ := data.GetInt8(key)
return value
}
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)
if err != nil { if err != nil {
@ -183,6 +233,11 @@ func (data Data) GetUint8(key string) (uint8, error) {
return uint8(value), nil return uint8(value), nil
} }
func (data Data) MustGetUint8(key string) uint8 {
value, _ := data.GetUint8(key)
return value
}
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)
if err != nil { if err != nil {
@ -197,6 +252,11 @@ func (data Data) GetBool(key string) (bool, error) {
return false, ErrFormat return false, ErrFormat
} }
func (data Data) MustGetBool(key string) bool {
value, _ := data.GetBool(key)
return value
}
func (data Data) GetTimestamp(key string) (Timestamp, error) { func (data Data) GetTimestamp(key string) (Timestamp, error) {
value, err := data.GetInt64(key) value, err := data.GetInt64(key)
if err != nil { if err != nil {
@ -205,3 +265,8 @@ func (data Data) GetTimestamp(key string) (Timestamp, error) {
return Timestamp(value), nil return Timestamp(value), nil
} }
func (data Data) MustGetTimestamp(key string) Timestamp {
value, _ := data.GetTimestamp(key)
return value
}

Loading…
Cancel
Save