调整map
This commit is contained in:
parent
096b1552f4
commit
25936d457a
3
init.go
3
init.go
@ -26,6 +26,8 @@ var (
|
||||
Time *ownTime
|
||||
// URL ...
|
||||
URL *ownURL
|
||||
// Map ...
|
||||
Map *ownMap
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -38,4 +40,5 @@ func init() {
|
||||
Struct = &ownStruct{}
|
||||
Time = &ownTime{}
|
||||
URL = &ownURL{}
|
||||
Map = &ownMap{}
|
||||
}
|
||||
|
66
map.go
66
map.go
@ -11,12 +11,20 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// ownMap ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:53 2022/5/14
|
||||
type ownMap struct {
|
||||
}
|
||||
|
||||
// Exist 检测一个key在map中是否存在
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 4:52 下午 2021/11/16
|
||||
func Exist(source map[interface{}]interface{}, key interface{}) bool {
|
||||
func (om *ownMap) Exist(source map[interface{}]interface{}, key interface{}) bool {
|
||||
if nil == source {
|
||||
return false
|
||||
}
|
||||
@ -31,9 +39,9 @@ func Exist(source map[interface{}]interface{}, key interface{}) bool {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 4:30 下午 2021/11/16
|
||||
func GetInt(source map[interface{}]interface{}, key interface{}, defaultVal int) int {
|
||||
func (om *ownMap) GetInt(source map[interface{}]interface{}, key interface{}, defaultVal int) int {
|
||||
var result int
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -44,9 +52,9 @@ func GetInt(source map[interface{}]interface{}, key interface{}, defaultVal int)
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 4:59 下午 2021/11/16
|
||||
func GetInt8(source map[interface{}]interface{}, key interface{}, defaultVal int8) int8 {
|
||||
func (om *ownMap) GetInt8(source map[interface{}]interface{}, key interface{}, defaultVal int8) int8 {
|
||||
var result int8
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -57,9 +65,9 @@ func GetInt8(source map[interface{}]interface{}, key interface{}, defaultVal int
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 4:59 下午 2021/11/16
|
||||
func GetInt16(source map[interface{}]interface{}, key interface{}, defaultVal int16) int16 {
|
||||
func (om *ownMap) GetInt16(source map[interface{}]interface{}, key interface{}, defaultVal int16) int16 {
|
||||
var result int16
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -70,9 +78,9 @@ func GetInt16(source map[interface{}]interface{}, key interface{}, defaultVal in
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 5:00 下午 2021/11/16
|
||||
func GetInt32(source map[interface{}]interface{}, key interface{}, defaultVal int32) int32 {
|
||||
func (om *ownMap) GetInt32(source map[interface{}]interface{}, key interface{}, defaultVal int32) int32 {
|
||||
var result int32
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -83,9 +91,9 @@ func GetInt32(source map[interface{}]interface{}, key interface{}, defaultVal in
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 5:00 下午 2021/11/16
|
||||
func GetInt64(source map[interface{}]interface{}, key interface{}, defaultVal int64) int64 {
|
||||
func (om *ownMap) GetInt64(source map[interface{}]interface{}, key interface{}, defaultVal int64) int64 {
|
||||
var result int64
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -96,9 +104,9 @@ func GetInt64(source map[interface{}]interface{}, key interface{}, defaultVal in
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 5:01 下午 2021/11/16
|
||||
func GetUint(source map[interface{}]interface{}, key interface{}, defaultVal uint) uint {
|
||||
func (om *ownMap) GetUint(source map[interface{}]interface{}, key interface{}, defaultVal uint) uint {
|
||||
var result uint
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -109,9 +117,9 @@ func GetUint(source map[interface{}]interface{}, key interface{}, defaultVal uin
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 5:01 下午 2021/11/16
|
||||
func GetUint8(source map[interface{}]interface{}, key interface{}, defaultVal uint8) uint8 {
|
||||
func (om *ownMap) GetUint8(source map[interface{}]interface{}, key interface{}, defaultVal uint8) uint8 {
|
||||
var result uint8
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -122,9 +130,9 @@ func GetUint8(source map[interface{}]interface{}, key interface{}, defaultVal ui
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 5:02 下午 2021/11/16
|
||||
func GetUint16(source map[interface{}]interface{}, key interface{}, defaultVal uint16) uint16 {
|
||||
func (om *ownMap) GetUint16(source map[interface{}]interface{}, key interface{}, defaultVal uint16) uint16 {
|
||||
var result uint16
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -135,9 +143,9 @@ func GetUint16(source map[interface{}]interface{}, key interface{}, defaultVal u
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 5:02 下午 2021/11/16
|
||||
func GetUint32(source map[interface{}]interface{}, key interface{}, defaultVal uint32) uint32 {
|
||||
func (om *ownMap) GetUint32(source map[interface{}]interface{}, key interface{}, defaultVal uint32) uint32 {
|
||||
var result uint32
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -148,9 +156,9 @@ func GetUint32(source map[interface{}]interface{}, key interface{}, defaultVal u
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 5:03 下午 2021/11/16
|
||||
func GetUint64(source map[interface{}]interface{}, key interface{}, defaultVal uint64) uint64 {
|
||||
func (om *ownMap) GetUint64(source map[interface{}]interface{}, key interface{}, defaultVal uint64) uint64 {
|
||||
var result uint64
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -161,9 +169,9 @@ func GetUint64(source map[interface{}]interface{}, key interface{}, defaultVal u
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 5:03 下午 2021/11/16
|
||||
func GetFloat32(source map[interface{}]interface{}, key interface{}, defaultVal float32) float32 {
|
||||
func (om *ownMap) GetFloat32(source map[interface{}]interface{}, key interface{}, defaultVal float32) float32 {
|
||||
var result float32
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -174,9 +182,9 @@ func GetFloat32(source map[interface{}]interface{}, key interface{}, defaultVal
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 5:04 下午 2021/11/16
|
||||
func GetFloat64(source map[interface{}]interface{}, key interface{}, defaultVal float64) float64 {
|
||||
func (om *ownMap) GetFloat64(source map[interface{}]interface{}, key interface{}, defaultVal float64) float64 {
|
||||
var result float64
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -187,9 +195,9 @@ func GetFloat64(source map[interface{}]interface{}, key interface{}, defaultVal
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 5:07 下午 2021/11/16
|
||||
func GetString(source map[interface{}]interface{}, key interface{}, defaultVal string) string {
|
||||
func (om *ownMap) GetString(source map[interface{}]interface{}, key interface{}, defaultVal string) string {
|
||||
var result string
|
||||
if err := GetDataWithReceiver(source, key, &result); nil != err {
|
||||
if err := om.GetDataWithReceiver(source, key, &result); nil != err {
|
||||
return defaultVal
|
||||
}
|
||||
return result
|
||||
@ -200,8 +208,8 @@ func GetString(source map[interface{}]interface{}, key interface{}, defaultVal s
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 4:54 下午 2021/11/16
|
||||
func GetDataWithReceiver(source map[interface{}]interface{}, key interface{}, receiver interface{}) error {
|
||||
if !Exist(source, key) {
|
||||
func (om *ownMap) GetDataWithReceiver(source map[interface{}]interface{}, key interface{}, receiver interface{}) error {
|
||||
if !om.Exist(source, key) {
|
||||
return errors.New("key is not found")
|
||||
}
|
||||
return ConvertAssign(receiver, source[key])
|
||||
|
Loading…
Reference in New Issue
Block a user