管理端初步
This commit is contained in:
parent
822d9708e4
commit
66c4b177c1
@ -6,7 +6,6 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" readonly="true" id="03ed5703-81a1-441b-849c-c426276586b7" name="Default" comment="">
|
<list default="true" readonly="true" id="03ed5703-81a1-441b-849c-c426276586b7" name="Default" comment="">
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/config/config.json" afterPath="$PROJECT_DIR$/config/config.json" />
|
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/example/main.go" afterPath="$PROJECT_DIR$/example/main.go" />
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/example/main.go" afterPath="$PROJECT_DIR$/example/main.go" />
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/map.go" afterPath="$PROJECT_DIR$/map.go" />
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/map.go" afterPath="$PROJECT_DIR$/map.go" />
|
||||||
</list>
|
</list>
|
||||||
@ -50,10 +49,10 @@
|
|||||||
<file leaf-file-name="map.go" pinned="false" current-in-tab="true">
|
<file leaf-file-name="map.go" pinned="false" current-in-tab="true">
|
||||||
<entry file="file://$PROJECT_DIR$/map.go">
|
<entry file="file://$PROJECT_DIR$/map.go">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="184">
|
<state relative-caret-position="303">
|
||||||
<caret line="47" column="16" lean-forward="false" selection-start-line="47" selection-start-column="16" selection-end-line="47" selection-end-column="16" />
|
<caret line="43" column="0" lean-forward="true" selection-start-line="43" selection-start-column="0" selection-end-line="43" selection-end-column="0" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#16#74#0" expanded="true" />
|
<element signature="e#16#64#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
@ -62,10 +61,10 @@
|
|||||||
<file leaf-file-name="main.go" pinned="false" current-in-tab="false">
|
<file leaf-file-name="main.go" pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/example/main.go">
|
<entry file="file://$PROJECT_DIR$/example/main.go">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="85">
|
<state relative-caret-position="238">
|
||||||
<caret line="13" column="7" lean-forward="true" selection-start-line="13" selection-start-column="7" selection-end-line="13" selection-end-column="7" />
|
<caret line="14" column="17" lean-forward="false" selection-start-line="14" selection-start-column="17" selection-end-line="14" selection-end-column="17" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#14#100#0" expanded="true" />
|
<element signature="e#14#102#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
@ -84,8 +83,8 @@
|
|||||||
<file leaf-file-name="objtoobj.go" pinned="false" current-in-tab="false">
|
<file leaf-file-name="objtoobj.go" pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/objtoobj.go">
|
<entry file="file://$PROJECT_DIR$/objtoobj.go">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="308">
|
<state relative-caret-position="493">
|
||||||
<caret line="32" column="5" lean-forward="false" selection-start-line="32" selection-start-column="5" selection-end-line="32" selection-end-column="5" />
|
<caret line="163" column="20" lean-forward="false" selection-start-line="163" selection-start-column="20" selection-end-line="163" selection-end-column="20" />
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
@ -125,7 +124,7 @@
|
|||||||
<entry file="file://$PROJECT_DIR$/cache_memory.go">
|
<entry file="file://$PROJECT_DIR$/cache_memory.go">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="816">
|
<state relative-caret-position="816">
|
||||||
<caret line="92" column="1" lean-forward="true" selection-start-line="92" selection-start-column="1" selection-end-line="92" selection-end-column="1" />
|
<caret line="92" column="1" lean-forward="false" selection-start-line="92" selection-start-column="1" selection-end-line="92" selection-end-column="1" />
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
@ -184,8 +183,8 @@
|
|||||||
<option value="$PROJECT_DIR$/error.go" />
|
<option value="$PROJECT_DIR$/error.go" />
|
||||||
<option value="$PROJECT_DIR$/const.go" />
|
<option value="$PROJECT_DIR$/const.go" />
|
||||||
<option value="$PROJECT_DIR$/session.go" />
|
<option value="$PROJECT_DIR$/session.go" />
|
||||||
<option value="$PROJECT_DIR$/example/main.go" />
|
|
||||||
<option value="$PROJECT_DIR$/map.go" />
|
<option value="$PROJECT_DIR$/map.go" />
|
||||||
|
<option value="$PROJECT_DIR$/example/main.go" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
@ -451,7 +450,7 @@
|
|||||||
<workItem from="1504252839700" duration="18000" />
|
<workItem from="1504252839700" duration="18000" />
|
||||||
<workItem from="1504488004086" duration="365000" />
|
<workItem from="1504488004086" duration="365000" />
|
||||||
<workItem from="1504488391347" duration="840000" />
|
<workItem from="1504488391347" duration="840000" />
|
||||||
<workItem from="1504575702799" duration="3525000" />
|
<workItem from="1504575702799" duration="4395000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001">
|
<task id="LOCAL-00001">
|
||||||
<created>1500458878821</created>
|
<created>1500458878821</created>
|
||||||
@ -600,11 +599,18 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1504575745842</updated>
|
<updated>1504575745842</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="22" />
|
<task id="LOCAL-00022" summary="管理端初步">
|
||||||
|
<created>1504579259295</created>
|
||||||
|
<option name="number" value="00022" />
|
||||||
|
<option name="presentableId" value="LOCAL-00022" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1504579259295</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="23" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TimeTrackingManager">
|
<component name="TimeTrackingManager">
|
||||||
<option name="totallyTimeSpent" value="81063000" />
|
<option name="totallyTimeSpent" value="81933000" />
|
||||||
</component>
|
</component>
|
||||||
<component name="TodoView">
|
<component name="TodoView">
|
||||||
<todo-panel id="selected-file">
|
<todo-panel id="selected-file">
|
||||||
@ -623,7 +629,7 @@
|
|||||||
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32846716" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
|
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32846716" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
|
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
|
||||||
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.63343716" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.6330179" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32912722" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32912722" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.24972437" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.24972437" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32846716" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32846716" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
||||||
@ -961,14 +967,6 @@
|
|||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/objtoobj.go">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<state relative-caret-position="308">
|
|
||||||
<caret line="32" column="5" lean-forward="false" selection-start-line="32" selection-start-column="5" selection-end-line="32" selection-end-column="5" />
|
|
||||||
<folding />
|
|
||||||
</state>
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
<entry file="file://$PROJECT_DIR$/session.go">
|
<entry file="file://$PROJECT_DIR$/session.go">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="969">
|
<state relative-caret-position="969">
|
||||||
@ -980,7 +978,7 @@
|
|||||||
<entry file="file://$PROJECT_DIR$/cache_memory.go">
|
<entry file="file://$PROJECT_DIR$/cache_memory.go">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="816">
|
<state relative-caret-position="816">
|
||||||
<caret line="92" column="1" lean-forward="true" selection-start-line="92" selection-start-column="1" selection-end-line="92" selection-end-column="1" />
|
<caret line="92" column="1" lean-forward="false" selection-start-line="92" selection-start-column="1" selection-end-line="92" selection-end-column="1" />
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
@ -1001,22 +999,30 @@
|
|||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/objtoobj.go">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="493">
|
||||||
|
<caret line="163" column="20" lean-forward="false" selection-start-line="163" selection-start-column="20" selection-end-line="163" selection-end-column="20" />
|
||||||
|
<folding />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/example/main.go">
|
<entry file="file://$PROJECT_DIR$/example/main.go">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="85">
|
<state relative-caret-position="238">
|
||||||
<caret line="13" column="7" lean-forward="true" selection-start-line="13" selection-start-column="7" selection-end-line="13" selection-end-column="7" />
|
<caret line="14" column="17" lean-forward="false" selection-start-line="14" selection-start-column="17" selection-end-line="14" selection-end-column="17" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#14#100#0" expanded="true" />
|
<element signature="e#14#102#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/map.go">
|
<entry file="file://$PROJECT_DIR$/map.go">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="184">
|
<state relative-caret-position="303">
|
||||||
<caret line="47" column="16" lean-forward="false" selection-start-line="47" selection-start-column="16" selection-end-line="47" selection-end-column="16" />
|
<caret line="43" column="0" lean-forward="true" selection-start-line="43" selection-start-column="0" selection-end-line="43" selection-end-column="0" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#16#74#0" expanded="true" />
|
<element signature="e#16#64#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -5,20 +5,27 @@ import (
|
|||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"go.hoteas.com/hotime"
|
"go.hoteas.com/hotime"
|
||||||
"time"
|
"time"
|
||||||
"fmt"
|
//"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
a:=hotime.Map{}
|
a:=hotime.Map{}
|
||||||
a.Get("y")
|
a.Put("x",1)
|
||||||
for i:=0;i<300 ;i++ {
|
for i:=0;i<30 ;i++ {
|
||||||
go func() {
|
go func() {
|
||||||
for j:=0;j<30 ;j++ {
|
for j:=0;j<30 ;j++ {
|
||||||
if j/2==0{
|
if j/2==0{
|
||||||
a.Put("x","1")
|
hotime.SafeMutex("test", func() interface{} {
|
||||||
}else {
|
|
||||||
fmt.Println(a.GetInt64("x"))
|
a.Put("x","1")
|
||||||
|
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}else {
|
||||||
|
//fmt.Println(a.GetInt64("x"))
|
||||||
|
a.Delete("x")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
160
map.go
160
map.go
@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"reflect"
|
"reflect"
|
||||||
//"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//hotime的常用map
|
//hotime的常用map
|
||||||
@ -12,12 +11,11 @@ type Map map[string]interface{}
|
|||||||
|
|
||||||
//获取string
|
//获取string
|
||||||
func (this Map) GetString(key string, err ...*Error) string {
|
func (this Map) GetString(key string, err ...*Error) string {
|
||||||
return SafeMutex(this.GetTag(), func() interface{} {
|
|
||||||
if len(err) != 0 {
|
if len(err) != 0 {
|
||||||
err[0].SetError(nil)
|
err[0].SetError(nil)
|
||||||
}
|
}
|
||||||
return ObjToStr((this)[key])
|
return ObjToStr((this)[key])
|
||||||
}).(string)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,159 +26,109 @@ func (this *Map) Pointer() *Map {
|
|||||||
|
|
||||||
//增加接口
|
//增加接口
|
||||||
func (this Map) Put(key string, value interface{}) {
|
func (this Map) Put(key string, value interface{}) {
|
||||||
SafeMutex(this.GetTag(), func() interface{} {
|
//if this==nil{
|
||||||
this[key] = value
|
// this=Map{}
|
||||||
return nil
|
//}
|
||||||
})
|
this[key] = value
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除接口
|
//删除接口
|
||||||
func (this Map) Delete(key string) {
|
func (this Map) Delete(key string) {
|
||||||
SafeMutex(this.GetTag(), func() interface{} {
|
delete(this, key)
|
||||||
delete(this, key)
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//唯一标志
|
|
||||||
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
|
//获取Int
|
||||||
func (this Map) GetInt(key string, err ...*Error) int {
|
func (this Map) GetInt(key string, err ...*Error) int {
|
||||||
|
v := ObjToInt((this)[key], err...)
|
||||||
|
|
||||||
return SafeMutex(this.GetTag(), func() interface{} {
|
return v
|
||||||
v := ObjToInt((this)[key], err...)
|
|
||||||
return v
|
|
||||||
}).(int)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Int
|
//获取Int
|
||||||
func (this Map) GetInt64(key string, err ...*Error) int64 {
|
func (this Map) GetInt64(key string, err ...*Error) int64 {
|
||||||
|
v := ObjToInt64((this)[key], err...)
|
||||||
return SafeMutex(this.GetTag(), func() interface{} {
|
return v
|
||||||
v := ObjToInt64((this)[key], err...)
|
|
||||||
return v
|
|
||||||
}).(int64)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Float64
|
//获取Float64
|
||||||
func (this Map) GetFloat64(key string, err ...*Error) float64 {
|
func (this Map) GetFloat64(key string, err ...*Error) float64 {
|
||||||
|
|
||||||
return SafeMutex(this.GetTag(), func() interface{} {
|
v := ObjToFloat64((this)[key], err...)
|
||||||
v := ObjToFloat64((this)[key], err...)
|
|
||||||
return v
|
return v
|
||||||
}).(float64)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) GetSlice(key string, err ...*Error) Slice {
|
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
|
//var v Slice
|
||||||
if res != nil {
|
v := ObjToSlice((this)[key], err...)
|
||||||
return res.(Slice)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) GetMap(key string, err ...*Error) Map {
|
func (this Map) GetMap(key string, err ...*Error) Map {
|
||||||
|
//var data Slice
|
||||||
|
|
||||||
res := SafeMutex(this.GetTag(), func() interface{} {
|
v := ObjToMap((this)[key], err...)
|
||||||
v := ObjToMap((this)[key], err...)
|
|
||||||
return v
|
|
||||||
})
|
|
||||||
//var v Slice
|
|
||||||
if res != nil {
|
|
||||||
return res.(Map)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) Get(key string, err ...*Error) interface{} {
|
func (this Map) Get(key string, err ...*Error) interface{} {
|
||||||
|
|
||||||
res := SafeMutex(this.GetTag(), func() interface{} {
|
if v, ok := (this)[key]; ok {
|
||||||
if v, ok := (this)[key]; ok {
|
return v
|
||||||
return v
|
}
|
||||||
}
|
e := errors.New("没有存储key及对应的数据")
|
||||||
e := errors.New("没有存储key及对应的数据")
|
|
||||||
|
|
||||||
if len(err) != 0 {
|
if len(err) != 0 {
|
||||||
err[0].SetError(e)
|
err[0].SetError(e)
|
||||||
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//请传递指针过来
|
//请传递指针过来
|
||||||
func (this Map) ToStruct(stct interface{}) {
|
func (this Map) ToStruct(stct interface{}) {
|
||||||
|
|
||||||
SafeMutex(this.GetTag(), func() interface{} {
|
data := reflect.ValueOf(stct).Elem()
|
||||||
data := reflect.ValueOf(stct).Elem()
|
for k, v := range this {
|
||||||
for k, v := range this {
|
ks := StrFirstToUpper(k)
|
||||||
ks := StrFirstToUpper(k)
|
dkey := data.FieldByName(ks)
|
||||||
dkey := data.FieldByName(ks)
|
if !dkey.IsValid() {
|
||||||
if !dkey.IsValid() {
|
continue
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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 {
|
func (this Map) ToJsonString() string {
|
||||||
res := SafeMutex(this.GetTag(), func() interface{} {
|
return ObjToStr(this)
|
||||||
return ObjToStr(this)
|
|
||||||
})
|
|
||||||
return res.(string)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) JsonToMap(jsonStr string, err ...*Error) {
|
func (this Map) JsonToMap(jsonStr string, err ...*Error) {
|
||||||
|
e := json.Unmarshal([]byte(jsonStr), &this)
|
||||||
SafeMutex(this.GetTag(), func() interface{} {
|
if e != nil && len(err) != 0 {
|
||||||
e := json.Unmarshal([]byte(jsonStr), &this)
|
err[0].SetError(e)
|
||||||
if e != nil && len(err) != 0 {
|
}
|
||||||
err[0].SetError(e)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user