interface => any
This commit is contained in:
parent
ce2d84d282
commit
28a6c68e38
48
abstruct.go
48
abstruct.go
@ -13,38 +13,38 @@ package easymap
|
||||
//
|
||||
// Date : 9:56 下午 2021/2/23
|
||||
type EasyMap interface {
|
||||
Get(key interface{}) (interface{}, bool)
|
||||
GetWithReceiver(key interface{}, dest interface{}) error
|
||||
GetUint(key interface{}) (uint, error)
|
||||
GetUint8(key interface{}) (uint8, error)
|
||||
GetUint16(key interface{}) (uint16, error)
|
||||
GetUint32(key interface{}) (uint32, error)
|
||||
GetUint64(key interface{}) (uint64, error)
|
||||
GetInt(key interface{}) (int, error)
|
||||
GetInt8(key interface{}) (int8, error)
|
||||
GetInt16(key interface{}) (int16, error)
|
||||
GetInt32(key interface{}) (int32, error)
|
||||
GetInt64(key interface{}) (int64, error)
|
||||
GetFloat32(key interface{}) (float32, error)
|
||||
GetFloat64(key interface{}) (float64, error)
|
||||
GetBool(key interface{}) (bool, error)
|
||||
GetString(key interface{}) (string, error)
|
||||
Set(key interface{}, value interface{})
|
||||
Del(key interface{})
|
||||
Exist(key interface{}) bool
|
||||
Get(key any) (any, bool)
|
||||
GetWithReceiver(key any, dest any) error
|
||||
GetUint(key any) (uint, error)
|
||||
GetUint8(key any) (uint8, error)
|
||||
GetUint16(key any) (uint16, error)
|
||||
GetUint32(key any) (uint32, error)
|
||||
GetUint64(key any) (uint64, error)
|
||||
GetInt(key any) (int, error)
|
||||
GetInt8(key any) (int8, error)
|
||||
GetInt16(key any) (int16, error)
|
||||
GetInt32(key any) (int32, error)
|
||||
GetInt64(key any) (int64, error)
|
||||
GetFloat32(key any) (float32, error)
|
||||
GetFloat64(key any) (float64, error)
|
||||
GetBool(key any) (bool, error)
|
||||
GetString(key any) (string, error)
|
||||
Set(key any, value any)
|
||||
Del(key any)
|
||||
Exist(key any) bool
|
||||
Count() int
|
||||
GetAll() map[interface{}]interface{}
|
||||
GetAllForMapKeyString() map[string]interface{}
|
||||
GetAll() map[any]any
|
||||
GetAllForMapKeyString() map[string]any
|
||||
// Merge 合并数据
|
||||
Merge(mergeData ...EasyMap)
|
||||
// MergeWithReceiver 合并数据并转换
|
||||
MergeWithReceiver(receiver interface{}, mergeData ...EasyMap) error
|
||||
MergeWithReceiver(receiver any, mergeData ...EasyMap) error
|
||||
// Iterator 对数据的迭代
|
||||
Iterator(IteratorFunc)
|
||||
// ToStruct 转换成结构体
|
||||
ToStruct(receiver interface{}) error
|
||||
ToStruct(receiver any) error
|
||||
// ToString 转为字符串
|
||||
ToString() string
|
||||
// Filter 过滤数据
|
||||
Filter(ignoreFieldList []string, rewriteFieldTable map[string]string) map[string]interface{}
|
||||
Filter(ignoreFieldList []string, rewriteFieldTable map[string]string) map[string]any
|
||||
}
|
||||
|
66
common.go
66
common.go
@ -22,11 +22,11 @@ import (
|
||||
//
|
||||
// Date : 15:52 2023/12/14
|
||||
type common struct {
|
||||
normalDataTable []map[interface{}]interface{} // 普通数组
|
||||
syncMapDataTable []sync.Map // sync_map类型
|
||||
dataTableType string // 数据表类型
|
||||
segment int // 分片熟练
|
||||
lock *sync.RWMutex // 数据锁
|
||||
normalDataTable []map[any]any // 普通数组
|
||||
syncMapDataTable []sync.Map // sync_map类型
|
||||
dataTableType string // 数据表类型
|
||||
segment int // 分片熟练
|
||||
lock *sync.RWMutex // 数据锁
|
||||
}
|
||||
|
||||
// initLock ...
|
||||
@ -88,7 +88,7 @@ func (c *common) RUnlock() {
|
||||
c.lock.RUnlock()
|
||||
}
|
||||
|
||||
func (c *common) Get(key interface{}) (interface{}, bool) {
|
||||
func (c *common) Get(key any) (any, bool) {
|
||||
segmentIndex := util.Hash.GetHashIDMod(key, c.segment)
|
||||
c.RLock()
|
||||
defer c.RUnlock()
|
||||
@ -101,7 +101,7 @@ func (c *common) Get(key interface{}) (interface{}, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *common) GetWithReceiver(key interface{}, dest interface{}) error {
|
||||
func (c *common) GetWithReceiver(key any, dest any) error {
|
||||
if nil == dest {
|
||||
return errors.New("dest is nil")
|
||||
}
|
||||
@ -115,7 +115,7 @@ func (c *common) GetWithReceiver(key interface{}, dest interface{}) error {
|
||||
return util.ConvertAssign(dest, val)
|
||||
}
|
||||
|
||||
func (c *common) GetUint(key interface{}) (uint, error) {
|
||||
func (c *common) GetUint(key any) (uint, error) {
|
||||
var (
|
||||
val uint
|
||||
err error
|
||||
@ -124,7 +124,7 @@ func (c *common) GetUint(key interface{}) (uint, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetUint8(key interface{}) (uint8, error) {
|
||||
func (c *common) GetUint8(key any) (uint8, error) {
|
||||
var (
|
||||
val uint8
|
||||
err error
|
||||
@ -133,7 +133,7 @@ func (c *common) GetUint8(key interface{}) (uint8, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetUint16(key interface{}) (uint16, error) {
|
||||
func (c *common) GetUint16(key any) (uint16, error) {
|
||||
var (
|
||||
val uint16
|
||||
err error
|
||||
@ -142,7 +142,7 @@ func (c *common) GetUint16(key interface{}) (uint16, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetUint32(key interface{}) (uint32, error) {
|
||||
func (c *common) GetUint32(key any) (uint32, error) {
|
||||
var (
|
||||
val uint32
|
||||
err error
|
||||
@ -151,7 +151,7 @@ func (c *common) GetUint32(key interface{}) (uint32, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetUint64(key interface{}) (uint64, error) {
|
||||
func (c *common) GetUint64(key any) (uint64, error) {
|
||||
var (
|
||||
val uint64
|
||||
err error
|
||||
@ -160,7 +160,7 @@ func (c *common) GetUint64(key interface{}) (uint64, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetInt(key interface{}) (int, error) {
|
||||
func (c *common) GetInt(key any) (int, error) {
|
||||
var (
|
||||
val int
|
||||
err error
|
||||
@ -169,7 +169,7 @@ func (c *common) GetInt(key interface{}) (int, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetInt8(key interface{}) (int8, error) {
|
||||
func (c *common) GetInt8(key any) (int8, error) {
|
||||
var (
|
||||
val int8
|
||||
err error
|
||||
@ -178,7 +178,7 @@ func (c *common) GetInt8(key interface{}) (int8, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetInt16(key interface{}) (int16, error) {
|
||||
func (c *common) GetInt16(key any) (int16, error) {
|
||||
var (
|
||||
val int16
|
||||
err error
|
||||
@ -187,7 +187,7 @@ func (c *common) GetInt16(key interface{}) (int16, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetInt32(key interface{}) (int32, error) {
|
||||
func (c *common) GetInt32(key any) (int32, error) {
|
||||
var (
|
||||
val int32
|
||||
err error
|
||||
@ -196,7 +196,7 @@ func (c *common) GetInt32(key interface{}) (int32, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetInt64(key interface{}) (int64, error) {
|
||||
func (c *common) GetInt64(key any) (int64, error) {
|
||||
var (
|
||||
val int64
|
||||
err error
|
||||
@ -205,7 +205,7 @@ func (c *common) GetInt64(key interface{}) (int64, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetFloat32(key interface{}) (float32, error) {
|
||||
func (c *common) GetFloat32(key any) (float32, error) {
|
||||
var (
|
||||
val float32
|
||||
err error
|
||||
@ -214,7 +214,7 @@ func (c *common) GetFloat32(key interface{}) (float32, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetFloat64(key interface{}) (float64, error) {
|
||||
func (c *common) GetFloat64(key any) (float64, error) {
|
||||
var (
|
||||
val float64
|
||||
err error
|
||||
@ -223,7 +223,7 @@ func (c *common) GetFloat64(key interface{}) (float64, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetBool(key interface{}) (bool, error) {
|
||||
func (c *common) GetBool(key any) (bool, error) {
|
||||
var (
|
||||
val bool
|
||||
err error
|
||||
@ -232,7 +232,7 @@ func (c *common) GetBool(key interface{}) (bool, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) GetString(key interface{}) (string, error) {
|
||||
func (c *common) GetString(key any) (string, error) {
|
||||
var (
|
||||
val string
|
||||
err error
|
||||
@ -241,7 +241,7 @@ func (c *common) GetString(key interface{}) (string, error) {
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (c *common) Set(key interface{}, value interface{}) {
|
||||
func (c *common) Set(key any, value any) {
|
||||
segmentIndex := util.Hash.GetHashIDMod(key, c.segment)
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
@ -253,7 +253,7 @@ func (c *common) Set(key interface{}, value interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *common) Del(key interface{}) {
|
||||
func (c *common) Del(key any) {
|
||||
segmentIndex := util.Hash.GetHashIDMod(key, c.segment)
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
@ -264,7 +264,7 @@ func (c *common) Del(key interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *common) Exist(key interface{}) bool {
|
||||
func (c *common) Exist(key any) bool {
|
||||
_, exist := c.Get(key)
|
||||
return exist
|
||||
}
|
||||
@ -284,8 +284,8 @@ func (c *common) Count() int {
|
||||
return cnt
|
||||
}
|
||||
|
||||
func (c *common) GetAll() map[interface{}]interface{} {
|
||||
result := make(map[interface{}]interface{})
|
||||
func (c *common) GetAll() map[any]any {
|
||||
result := make(map[any]any)
|
||||
c.RLock()
|
||||
defer c.RUnlock()
|
||||
for i := 0; i < c.segment; i++ {
|
||||
@ -294,7 +294,7 @@ func (c *common) GetAll() map[interface{}]interface{} {
|
||||
result[k] = v
|
||||
}
|
||||
} else {
|
||||
c.syncMapDataTable[i].Range(func(key, value interface{}) bool {
|
||||
c.syncMapDataTable[i].Range(func(key, value any) bool {
|
||||
result[key] = value
|
||||
return true
|
||||
})
|
||||
@ -308,9 +308,9 @@ func (c *common) GetAll() map[interface{}]interface{} {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 9:48 下午 2021/9/15
|
||||
func (c *common) GetAllForMapKeyString() map[string]interface{} {
|
||||
func (c *common) GetAllForMapKeyString() map[string]any {
|
||||
fullData := c.GetAll()
|
||||
finalData := make(map[string]interface{})
|
||||
finalData := make(map[string]any)
|
||||
for k, v := range fullData {
|
||||
finalData[fmt.Sprintf("%v", k)] = v
|
||||
}
|
||||
@ -353,7 +353,7 @@ func (c *common) Iterator(handleFunc IteratorFunc) {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:42 2023/8/10
|
||||
func (c *common) ToStruct(receiver interface{}) error {
|
||||
func (c *common) ToStruct(receiver any) error {
|
||||
if nil == receiver {
|
||||
return errors.New("receiver is nil")
|
||||
}
|
||||
@ -380,14 +380,14 @@ func (c *common) ToString() string {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:25 2024/3/8
|
||||
func (c *common) Filter(ignoreFieldList []string, rewriteFieldTable map[string]string) map[string]interface{} {
|
||||
func (c *common) Filter(ignoreFieldList []string, rewriteFieldTable map[string]string) map[string]any {
|
||||
if nil == ignoreFieldList {
|
||||
ignoreFieldList = make([]string, 0)
|
||||
}
|
||||
if nil == rewriteFieldTable {
|
||||
rewriteFieldTable = make(map[string]string)
|
||||
}
|
||||
result := make(map[string]interface{})
|
||||
result := make(map[string]any)
|
||||
ignoreFieldTable := make(map[string]bool)
|
||||
for _, item := range ignoreFieldList {
|
||||
ignoreFieldTable[item] = true
|
||||
@ -425,7 +425,7 @@ func (c *common) Merge(mergeData ...EasyMap) {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:06 2024/3/11
|
||||
func (c *common) MergeWithReceiver(receiver interface{}, mergeData ...EasyMap) error {
|
||||
func (c *common) MergeWithReceiver(receiver any, mergeData ...EasyMap) error {
|
||||
c.Merge(mergeData...)
|
||||
if nil == receiver {
|
||||
return nil
|
||||
|
@ -8,7 +8,7 @@
|
||||
package easymap
|
||||
|
||||
// IteratorFunc 迭代函数, 返回值为是否继续迭代,true 继续迭代 false 终止后续迭代
|
||||
type IteratorFunc func(key interface{}, value interface{}) bool
|
||||
type IteratorFunc func(key any, value any) bool
|
||||
|
||||
const (
|
||||
normalDataTableType = "NORMAL"
|
||||
|
2
error.go
2
error.go
@ -17,7 +17,7 @@ import (
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 10:17 下午 2021/2/23
|
||||
func keyNotFound(key interface{}) error {
|
||||
func keyNotFound(key any) error {
|
||||
return fmt.Errorf("%v 未找到", key)
|
||||
}
|
||||
|
||||
|
@ -25,9 +25,9 @@ func NewSegment(segmentCnt int) (EasyMap, error) {
|
||||
lock: nil,
|
||||
},
|
||||
}
|
||||
em.normalDataTable = make([]map[interface{}]interface{}, segmentCnt)
|
||||
em.normalDataTable = make([]map[any]any, segmentCnt)
|
||||
for i := 0; i < segmentCnt; i++ {
|
||||
em.normalDataTable[i] = make(map[interface{}]interface{})
|
||||
em.normalDataTable[i] = make(map[any]any)
|
||||
}
|
||||
em.common.initLock()
|
||||
return em, nil
|
||||
|
Loading…
Reference in New Issue
Block a user