interface => any

This commit is contained in:
白茶清欢 2024-11-01 16:25:29 +08:00
parent ce2d84d282
commit 28a6c68e38
5 changed files with 61 additions and 61 deletions

View File

@ -13,38 +13,38 @@ package easymap
// //
// Date : 9:56 下午 2021/2/23 // Date : 9:56 下午 2021/2/23
type EasyMap interface { type EasyMap interface {
Get(key interface{}) (interface{}, bool) Get(key any) (any, bool)
GetWithReceiver(key interface{}, dest interface{}) error GetWithReceiver(key any, dest any) error
GetUint(key interface{}) (uint, error) GetUint(key any) (uint, error)
GetUint8(key interface{}) (uint8, error) GetUint8(key any) (uint8, error)
GetUint16(key interface{}) (uint16, error) GetUint16(key any) (uint16, error)
GetUint32(key interface{}) (uint32, error) GetUint32(key any) (uint32, error)
GetUint64(key interface{}) (uint64, error) GetUint64(key any) (uint64, error)
GetInt(key interface{}) (int, error) GetInt(key any) (int, error)
GetInt8(key interface{}) (int8, error) GetInt8(key any) (int8, error)
GetInt16(key interface{}) (int16, error) GetInt16(key any) (int16, error)
GetInt32(key interface{}) (int32, error) GetInt32(key any) (int32, error)
GetInt64(key interface{}) (int64, error) GetInt64(key any) (int64, error)
GetFloat32(key interface{}) (float32, error) GetFloat32(key any) (float32, error)
GetFloat64(key interface{}) (float64, error) GetFloat64(key any) (float64, error)
GetBool(key interface{}) (bool, error) GetBool(key any) (bool, error)
GetString(key interface{}) (string, error) GetString(key any) (string, error)
Set(key interface{}, value interface{}) Set(key any, value any)
Del(key interface{}) Del(key any)
Exist(key interface{}) bool Exist(key any) bool
Count() int Count() int
GetAll() map[interface{}]interface{} GetAll() map[any]any
GetAllForMapKeyString() map[string]interface{} GetAllForMapKeyString() map[string]any
// Merge 合并数据 // Merge 合并数据
Merge(mergeData ...EasyMap) Merge(mergeData ...EasyMap)
// MergeWithReceiver 合并数据并转换 // MergeWithReceiver 合并数据并转换
MergeWithReceiver(receiver interface{}, mergeData ...EasyMap) error MergeWithReceiver(receiver any, mergeData ...EasyMap) error
// Iterator 对数据的迭代 // Iterator 对数据的迭代
Iterator(IteratorFunc) Iterator(IteratorFunc)
// ToStruct 转换成结构体 // ToStruct 转换成结构体
ToStruct(receiver interface{}) error ToStruct(receiver any) error
// ToString 转为字符串 // ToString 转为字符串
ToString() string ToString() string
// Filter 过滤数据 // Filter 过滤数据
Filter(ignoreFieldList []string, rewriteFieldTable map[string]string) map[string]interface{} Filter(ignoreFieldList []string, rewriteFieldTable map[string]string) map[string]any
} }

View File

@ -22,11 +22,11 @@ import (
// //
// Date : 15:52 2023/12/14 // Date : 15:52 2023/12/14
type common struct { type common struct {
normalDataTable []map[interface{}]interface{} // 普通数组 normalDataTable []map[any]any // 普通数组
syncMapDataTable []sync.Map // sync_map类型 syncMapDataTable []sync.Map // sync_map类型
dataTableType string // 数据表类型 dataTableType string // 数据表类型
segment int // 分片熟练 segment int // 分片熟练
lock *sync.RWMutex // 数据锁 lock *sync.RWMutex // 数据锁
} }
// initLock ... // initLock ...
@ -88,7 +88,7 @@ func (c *common) RUnlock() {
c.lock.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) segmentIndex := util.Hash.GetHashIDMod(key, c.segment)
c.RLock() c.RLock()
defer c.RUnlock() 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 { if nil == dest {
return errors.New("dest is nil") return errors.New("dest is nil")
} }
@ -115,7 +115,7 @@ func (c *common) GetWithReceiver(key interface{}, dest interface{}) error {
return util.ConvertAssign(dest, val) return util.ConvertAssign(dest, val)
} }
func (c *common) GetUint(key interface{}) (uint, error) { func (c *common) GetUint(key any) (uint, error) {
var ( var (
val uint val uint
err error err error
@ -124,7 +124,7 @@ func (c *common) GetUint(key interface{}) (uint, error) {
return val, err return val, err
} }
func (c *common) GetUint8(key interface{}) (uint8, error) { func (c *common) GetUint8(key any) (uint8, error) {
var ( var (
val uint8 val uint8
err error err error
@ -133,7 +133,7 @@ func (c *common) GetUint8(key interface{}) (uint8, error) {
return val, err return val, err
} }
func (c *common) GetUint16(key interface{}) (uint16, error) { func (c *common) GetUint16(key any) (uint16, error) {
var ( var (
val uint16 val uint16
err error err error
@ -142,7 +142,7 @@ func (c *common) GetUint16(key interface{}) (uint16, error) {
return val, err return val, err
} }
func (c *common) GetUint32(key interface{}) (uint32, error) { func (c *common) GetUint32(key any) (uint32, error) {
var ( var (
val uint32 val uint32
err error err error
@ -151,7 +151,7 @@ func (c *common) GetUint32(key interface{}) (uint32, error) {
return val, err return val, err
} }
func (c *common) GetUint64(key interface{}) (uint64, error) { func (c *common) GetUint64(key any) (uint64, error) {
var ( var (
val uint64 val uint64
err error err error
@ -160,7 +160,7 @@ func (c *common) GetUint64(key interface{}) (uint64, error) {
return val, err return val, err
} }
func (c *common) GetInt(key interface{}) (int, error) { func (c *common) GetInt(key any) (int, error) {
var ( var (
val int val int
err error err error
@ -169,7 +169,7 @@ func (c *common) GetInt(key interface{}) (int, error) {
return val, err return val, err
} }
func (c *common) GetInt8(key interface{}) (int8, error) { func (c *common) GetInt8(key any) (int8, error) {
var ( var (
val int8 val int8
err error err error
@ -178,7 +178,7 @@ func (c *common) GetInt8(key interface{}) (int8, error) {
return val, err return val, err
} }
func (c *common) GetInt16(key interface{}) (int16, error) { func (c *common) GetInt16(key any) (int16, error) {
var ( var (
val int16 val int16
err error err error
@ -187,7 +187,7 @@ func (c *common) GetInt16(key interface{}) (int16, error) {
return val, err return val, err
} }
func (c *common) GetInt32(key interface{}) (int32, error) { func (c *common) GetInt32(key any) (int32, error) {
var ( var (
val int32 val int32
err error err error
@ -196,7 +196,7 @@ func (c *common) GetInt32(key interface{}) (int32, error) {
return val, err return val, err
} }
func (c *common) GetInt64(key interface{}) (int64, error) { func (c *common) GetInt64(key any) (int64, error) {
var ( var (
val int64 val int64
err error err error
@ -205,7 +205,7 @@ func (c *common) GetInt64(key interface{}) (int64, error) {
return val, err return val, err
} }
func (c *common) GetFloat32(key interface{}) (float32, error) { func (c *common) GetFloat32(key any) (float32, error) {
var ( var (
val float32 val float32
err error err error
@ -214,7 +214,7 @@ func (c *common) GetFloat32(key interface{}) (float32, error) {
return val, err return val, err
} }
func (c *common) GetFloat64(key interface{}) (float64, error) { func (c *common) GetFloat64(key any) (float64, error) {
var ( var (
val float64 val float64
err error err error
@ -223,7 +223,7 @@ func (c *common) GetFloat64(key interface{}) (float64, error) {
return val, err return val, err
} }
func (c *common) GetBool(key interface{}) (bool, error) { func (c *common) GetBool(key any) (bool, error) {
var ( var (
val bool val bool
err error err error
@ -232,7 +232,7 @@ func (c *common) GetBool(key interface{}) (bool, error) {
return val, err return val, err
} }
func (c *common) GetString(key interface{}) (string, error) { func (c *common) GetString(key any) (string, error) {
var ( var (
val string val string
err error err error
@ -241,7 +241,7 @@ func (c *common) GetString(key interface{}) (string, error) {
return val, err 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) segmentIndex := util.Hash.GetHashIDMod(key, c.segment)
c.Lock() c.Lock()
defer c.Unlock() 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) segmentIndex := util.Hash.GetHashIDMod(key, c.segment)
c.Lock() c.Lock()
defer c.Unlock() 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) _, exist := c.Get(key)
return exist return exist
} }
@ -284,8 +284,8 @@ func (c *common) Count() int {
return cnt return cnt
} }
func (c *common) GetAll() map[interface{}]interface{} { func (c *common) GetAll() map[any]any {
result := make(map[interface{}]interface{}) result := make(map[any]any)
c.RLock() c.RLock()
defer c.RUnlock() defer c.RUnlock()
for i := 0; i < c.segment; i++ { for i := 0; i < c.segment; i++ {
@ -294,7 +294,7 @@ func (c *common) GetAll() map[interface{}]interface{} {
result[k] = v result[k] = v
} }
} else { } else {
c.syncMapDataTable[i].Range(func(key, value interface{}) bool { c.syncMapDataTable[i].Range(func(key, value any) bool {
result[key] = value result[key] = value
return true return true
}) })
@ -308,9 +308,9 @@ func (c *common) GetAll() map[interface{}]interface{} {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 9:48 下午 2021/9/15 // Date : 9:48 下午 2021/9/15
func (c *common) GetAllForMapKeyString() map[string]interface{} { func (c *common) GetAllForMapKeyString() map[string]any {
fullData := c.GetAll() fullData := c.GetAll()
finalData := make(map[string]interface{}) finalData := make(map[string]any)
for k, v := range fullData { for k, v := range fullData {
finalData[fmt.Sprintf("%v", k)] = v finalData[fmt.Sprintf("%v", k)] = v
} }
@ -353,7 +353,7 @@ func (c *common) Iterator(handleFunc IteratorFunc) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 15:42 2023/8/10 // Date : 15:42 2023/8/10
func (c *common) ToStruct(receiver interface{}) error { func (c *common) ToStruct(receiver any) error {
if nil == receiver { if nil == receiver {
return errors.New("receiver is nil") return errors.New("receiver is nil")
} }
@ -380,14 +380,14 @@ func (c *common) ToString() string {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 16:25 2024/3/8 // 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 { if nil == ignoreFieldList {
ignoreFieldList = make([]string, 0) ignoreFieldList = make([]string, 0)
} }
if nil == rewriteFieldTable { if nil == rewriteFieldTable {
rewriteFieldTable = make(map[string]string) rewriteFieldTable = make(map[string]string)
} }
result := make(map[string]interface{}) result := make(map[string]any)
ignoreFieldTable := make(map[string]bool) ignoreFieldTable := make(map[string]bool)
for _, item := range ignoreFieldList { for _, item := range ignoreFieldList {
ignoreFieldTable[item] = true ignoreFieldTable[item] = true
@ -425,7 +425,7 @@ func (c *common) Merge(mergeData ...EasyMap) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 11:06 2024/3/11 // 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...) c.Merge(mergeData...)
if nil == receiver { if nil == receiver {
return nil return nil

View File

@ -8,7 +8,7 @@
package easymap package easymap
// IteratorFunc 迭代函数, 返回值为是否继续迭代true 继续迭代 false 终止后续迭代 // IteratorFunc 迭代函数, 返回值为是否继续迭代true 继续迭代 false 终止后续迭代
type IteratorFunc func(key interface{}, value interface{}) bool type IteratorFunc func(key any, value any) bool
const ( const (
normalDataTableType = "NORMAL" normalDataTableType = "NORMAL"

View File

@ -17,7 +17,7 @@ import (
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 10:17 下午 2021/2/23 // Date : 10:17 下午 2021/2/23
func keyNotFound(key interface{}) error { func keyNotFound(key any) error {
return fmt.Errorf("%v 未找到", key) return fmt.Errorf("%v 未找到", key)
} }

View File

@ -25,9 +25,9 @@ func NewSegment(segmentCnt int) (EasyMap, error) {
lock: nil, lock: nil,
}, },
} }
em.normalDataTable = make([]map[interface{}]interface{}, segmentCnt) em.normalDataTable = make([]map[any]any, segmentCnt)
for i := 0; i < segmentCnt; i++ { for i := 0; i < segmentCnt; i++ {
em.normalDataTable[i] = make(map[interface{}]interface{}) em.normalDataTable[i] = make(map[any]any)
} }
em.common.initLock() em.common.initLock()
return em, nil return em, nil