diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 76d0dd9..3485330 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,7 +6,6 @@
-
@@ -50,10 +49,10 @@
-
-
+
+
-
+
@@ -62,10 +61,10 @@
-
-
+
+
-
+
@@ -84,8 +83,8 @@
-
-
+
+
@@ -125,7 +124,7 @@
-
+
@@ -184,8 +183,8 @@
-
+
@@ -451,7 +450,7 @@
-
+
1500458878821
@@ -600,11 +599,18 @@
1504575745842
-
+
+ 1504579259295
+
+
+
+ 1504579259295
+
+
-
+
@@ -623,7 +629,7 @@
-
+
@@ -961,14 +967,6 @@
-
-
-
-
-
-
-
-
@@ -980,7 +978,7 @@
-
+
@@ -1001,22 +999,30 @@
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
diff --git a/example/main.go b/example/main.go
index 0c45dd8..c7de1a7 100644
--- a/example/main.go
+++ b/example/main.go
@@ -5,20 +5,27 @@ import (
_ "github.com/go-sql-driver/mysql"
"go.hoteas.com/hotime"
"time"
- "fmt"
+ //"fmt"
)
func main() {
a:=hotime.Map{}
- a.Get("y")
- for i:=0;i<300 ;i++ {
+ a.Put("x",1)
+ for i:=0;i<30 ;i++ {
go func() {
for j:=0;j<30 ;j++ {
if j/2==0{
- a.Put("x","1")
- }else {
- fmt.Println(a.GetInt64("x"))
+ hotime.SafeMutex("test", func() interface{} {
+
+ a.Put("x","1")
+
+
+ return nil
+ })
+ }else {
+ //fmt.Println(a.GetInt64("x"))
+ a.Delete("x")
}
}
diff --git a/map.go b/map.go
index 515279b..c632a7d 100644
--- a/map.go
+++ b/map.go
@@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"reflect"
- //"time"
)
//hotime的常用map
@@ -12,12 +11,11 @@ type Map map[string]interface{}
//获取string
func (this Map) GetString(key string, err ...*Error) string {
- return SafeMutex(this.GetTag(), func() interface{} {
- if len(err) != 0 {
- err[0].SetError(nil)
- }
- return ObjToStr((this)[key])
- }).(string)
+
+ if len(err) != 0 {
+ err[0].SetError(nil)
+ }
+ return ObjToStr((this)[key])
}
@@ -28,159 +26,109 @@ func (this *Map) Pointer() *Map {
//增加接口
func (this Map) Put(key string, value interface{}) {
- SafeMutex(this.GetTag(), func() interface{} {
- this[key] = value
- return nil
- })
-
+ //if this==nil{
+ // this=Map{}
+ //}
+ this[key] = value
}
//删除接口
func (this Map) Delete(key string) {
- SafeMutex(this.GetTag(), func() interface{} {
- delete(this, key)
- return nil
- })
+ delete(this, key)
}
-//唯一标志
-func (this Map) GetTag() string {
-
- //return SafeMutex(MUTEX_MAP, func() interface{} {
- // if this[MUTEX_MAP] == nil {
- // this[MUTEX_MAP] = ObjToStr(time.Now().UnixNano())
- //
- // }
- // return ObjToStr(this[MUTEX_MAP])
- //}).(string)
- return MUTEX_MAP
- }
-
//获取Int
func (this Map) GetInt(key string, err ...*Error) int {
+ v := ObjToInt((this)[key], err...)
- return SafeMutex(this.GetTag(), func() interface{} {
- v := ObjToInt((this)[key], err...)
- return v
- }).(int)
+ return v
}
//获取Int
func (this Map) GetInt64(key string, err ...*Error) int64 {
-
- return SafeMutex(this.GetTag(), func() interface{} {
- v := ObjToInt64((this)[key], err...)
- return v
- }).(int64)
+ v := ObjToInt64((this)[key], err...)
+ return v
}
//获取Float64
func (this Map) GetFloat64(key string, err ...*Error) float64 {
- return SafeMutex(this.GetTag(), func() interface{} {
- v := ObjToFloat64((this)[key], err...)
- return v
- }).(float64)
+ v := ObjToFloat64((this)[key], err...)
+
+ return v
}
func (this Map) GetSlice(key string, err ...*Error) Slice {
- res := SafeMutex(this.GetTag(), func() interface{} {
- v := ObjToSlice((this)[key], err...)
- return v
- })
//var v Slice
- if res != nil {
- return res.(Slice)
- }
+ v := ObjToSlice((this)[key], err...)
- return nil
+ return v
}
func (this Map) GetMap(key string, err ...*Error) Map {
+ //var data Slice
- res := SafeMutex(this.GetTag(), func() interface{} {
- v := ObjToMap((this)[key], err...)
- return v
- })
- //var v Slice
- if res != nil {
- return res.(Map)
- }
+ v := ObjToMap((this)[key], err...)
- return nil
+ return v
}
func (this Map) Get(key string, err ...*Error) interface{} {
- res := SafeMutex(this.GetTag(), func() interface{} {
- if v, ok := (this)[key]; ok {
- return v
- }
- e := errors.New("没有存储key及对应的数据")
+ if v, ok := (this)[key]; ok {
+ return v
+ }
+ e := errors.New("没有存储key及对应的数据")
- if len(err) != 0 {
- err[0].SetError(e)
-
- }
- return nil
- })
-
- return res
+ if len(err) != 0 {
+ err[0].SetError(e)
+ }
+ return nil
}
//请传递指针过来
func (this Map) ToStruct(stct interface{}) {
- SafeMutex(this.GetTag(), func() interface{} {
- data := reflect.ValueOf(stct).Elem()
- for k, v := range this {
- ks := StrFirstToUpper(k)
- dkey := data.FieldByName(ks)
- if !dkey.IsValid() {
- continue
- }
- switch dkey.Type().String() {
- case "int":
- dkey.SetInt(this.GetInt64(k))
- case "int64":
- dkey.Set(reflect.ValueOf(this.GetInt64(k)))
- case "float64":
- dkey.Set(reflect.ValueOf(this.GetFloat64(k)))
- case "string":
- dkey.Set(reflect.ValueOf(this.GetString(k)))
- case "interface{}":
- dkey.Set(reflect.ValueOf(v))
- }
+ data := reflect.ValueOf(stct).Elem()
+ for k, v := range this {
+ ks := StrFirstToUpper(k)
+ dkey := data.FieldByName(ks)
+ if !dkey.IsValid() {
+ continue
}
- return nil
- })
+ switch dkey.Type().String() {
+ case "int":
+ dkey.SetInt(this.GetInt64(k))
+ case "int64":
+ dkey.Set(reflect.ValueOf(this.GetInt64(k)))
+ case "float64":
+ dkey.Set(reflect.ValueOf(this.GetFloat64(k)))
+ case "string":
+ dkey.Set(reflect.ValueOf(this.GetString(k)))
+ case "interface{}":
+ dkey.Set(reflect.ValueOf(v))
+ }
+ }
}
func (this Map) ToJsonString() string {
- res := SafeMutex(this.GetTag(), func() interface{} {
- return ObjToStr(this)
- })
- return res.(string)
+ return ObjToStr(this)
}
func (this Map) JsonToMap(jsonStr string, err ...*Error) {
-
- SafeMutex(this.GetTag(), func() interface{} {
- e := json.Unmarshal([]byte(jsonStr), &this)
- if e != nil && len(err) != 0 {
- err[0].SetError(e)
- }
- return nil
- })
+ e := json.Unmarshal([]byte(jsonStr), &this)
+ if e != nil && len(err) != 0 {
+ err[0].SetError(e)
+ }
}