diff --git a/.idea/libraries/GOPATH__hotime_.xml b/.idea/libraries/GOPATH__hotime_.xml
deleted file mode 100644
index 55a4127..0000000
--- a/.idea/libraries/GOPATH__hotime_.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 5a0d328..bbb8107 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,7 +5,12 @@
+
+
+
+
+
@@ -18,7 +23,6 @@
-
@@ -101,7 +105,7 @@
-
+
@@ -220,58 +224,19 @@
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
@@ -307,33 +272,21 @@
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -342,6 +295,23 @@
+
+
+ project
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -378,15 +348,6 @@
-
- project
-
-
-
-
-
-
-
@@ -407,9 +368,6 @@
false
-
-
-
@@ -476,6 +434,7 @@
+
1500458878821
@@ -663,7 +622,7 @@
-
+
@@ -677,16 +636,16 @@
-
+
-
+
-
+
@@ -701,7 +660,7 @@
-
+
@@ -919,7 +878,6 @@
-
@@ -990,7 +948,7 @@
-
+
diff --git a/application.go b/application.go
index 57526ba..0272ad7 100644
--- a/application.go
+++ b/application.go
@@ -33,7 +33,7 @@ func (this *Application) Run(router Router) {
//this.Port = port
this.Port = this.Config.GetString("port")
- if this.connectDbFunc != nil {
+ if this.connectDbFunc != nil && this.Db.DB.Ping() != nil {
this.Db.SetConnect(this.connectDbFunc)
}
@@ -57,6 +57,7 @@ func (this *Application) Run(router Router) {
//启动实例
func (this *Application) SetConnectDB(connect func(err ...*Error) *sql.DB) {
this.connectDbFunc = connect
+ this.Db.SetConnect(this.connectDbFunc)
}
//设置配置文件路径全路径或者相对路径
@@ -70,6 +71,10 @@ func (this *Application) SetSession(short CacheIns, Long CacheIns) {
func (this *Application) SetDefault(connect func(err ...*Error) *sql.DB) {
this.SetConfig()
this.connectDbFunc = connect
+ if this.connectDbFunc!=nil{
+ this.Db.SetConnect(this.connectDbFunc)
+ }
+
//防止手动设置缓存误伤
if this.CacheIns == nil {
this.SetCache(CacheIns(&CacheMemory{}))
diff --git a/objtoobj.go b/objtoobj.go
index 94c3191..e0f9445 100644
--- a/objtoobj.go
+++ b/objtoobj.go
@@ -1,13 +1,14 @@
package hotime
import (
+ "encoding/json"
"errors"
"strconv"
- "encoding/json"
+ "strings"
)
//仅限于hotime.Slice
-func ObjToMap(obj interface{},e... *Error) Map {
+func ObjToMap(obj interface{}, e ...*Error) Map {
var err error
var v Map
@@ -15,22 +16,24 @@ func ObjToMap(obj interface{},e... *Error) Map {
v = nil
err = errors.New("没有合适的转换对象!")
} else {
- switch obj.(type){
- case Map:v = obj.(Map)
- case map[string]interface {}:v=obj.(map[string]interface{})
+ switch obj.(type) {
+ case Map:
+ v = obj.(Map)
+ case map[string]interface{}:
+ v = obj.(map[string]interface{})
default:
v = nil
err = errors.New("没有合适的转换对象!")
}
}
- if(len(e)!=0){
+ if len(e) != 0 {
e[0].SetError(err)
}
return v
}
//仅限于hotime.Slice
-func ObjToSlice(obj interface{},e... *Error) Slice{
+func ObjToSlice(obj interface{}, e ...*Error) Slice {
var err error
var v Slice
@@ -41,21 +44,22 @@ func ObjToSlice(obj interface{},e... *Error) Slice{
switch obj.(type) {
case Slice:
v = obj.(Slice)
- case []interface {}:v=obj.([]interface{})
+ case []interface{}:
+ v = obj.([]interface{})
default:
v = nil
err = errors.New("没有合适的转换对象!")
}
}
- if(len(e)!=0){
+ if len(e) != 0 {
e[0].SetError(err)
}
return v
}
-func ObjToFloat64(obj interface{},e... *Error) float64 {
+func ObjToFloat64(obj interface{}, e ...*Error) float64 {
var err error
v := float64(0)
@@ -94,13 +98,13 @@ func ObjToFloat64(obj interface{},e... *Error) float64 {
err = errors.New("没有合适的转换对象!")
}
}
- if(len(e)!=0){
+ if len(e) != 0 {
e[0].SetError(err)
}
return v
}
-func ObjToInt64(obj interface{},e... *Error) int64 {
+func ObjToInt64(obj interface{}, e ...*Error) int64 {
var err error
v := int64(0)
@@ -138,13 +142,13 @@ func ObjToInt64(obj interface{},e... *Error) int64 {
err = errors.New("没有合适的转换对象!")
}
}
- if(len(e)!=0){
+ if len(e) != 0 {
e[0].SetError(err)
}
return v
}
-func ObjToInt(obj interface{},e... *Error) int {
+func ObjToInt(obj interface{}, e ...*Error) int {
var err error
v := 0
if obj == nil {
@@ -182,7 +186,7 @@ func ObjToInt(obj interface{},e... *Error) int {
}
}
- if(len(e)!=0){
+ if len(e) != 0 {
e[0].SetError(err)
}
return v
@@ -191,7 +195,7 @@ func ObjToInt(obj interface{},e... *Error) int {
func ObjToStr(obj interface{}) string {
// fmt.Println(reflect.ValueOf(obj).Type().String() )
str := ""
- if obj==nil{
+ if obj == nil {
return str
}
switch obj.(type) {
@@ -208,9 +212,9 @@ func ObjToStr(obj interface{}) string {
case float64:
str = strconv.FormatFloat(obj.(float64), 'f', 6, 64)
default:
- strbte,err:=json.Marshal(obj);
- if err==nil{
- str=string(strbte)
+ strbte, err := json.Marshal(obj)
+ if err == nil {
+ str = string(strbte)
}
}
@@ -218,9 +222,30 @@ func ObjToStr(obj interface{}) string {
return str
}
+//字符串数组: a1,a2,a3转["a1","a2","a3"]
+func StrArrayToJsonStr(a string) string {
+ if len(a) != 0 {
+ a = strings.Replace(a, ",", `","`, -1)
+ a = `["` + a + `"]`
+ } else {
+ a = "[]"
+ }
+ return a
+}
+
+//字符串数组: a1,a2,a3转["a1","a2","a3"]
+func JsonStrToStrArray(a string) string {
+ a = strings.Replace(a, `"`, "", -1)
+ if len(a)!=0{
+ a = Substr(a, 1, len(a)-2)
+ }
+
+ return a
+}
+
//字符串转int
func StrToInt(s string) (int, error) {
i, err := strconv.Atoi(s)
return i, err
-}
\ No newline at end of file
+}
diff --git a/slice.go b/slice.go
index 7f1ea25..a368001 100644
--- a/slice.go
+++ b/slice.go
@@ -62,10 +62,12 @@ func (this Slice) Put(key int, value interface{}) {
this[key] = value
}
-func (this Slice) GetJsonString() string {
+func (this Slice) ToJsonString() string {
return ObjToStr(this)
}
+
+
func (this Slice) JsonToSlice(jsonStr string) {
json.Unmarshal([]byte(jsonStr), &this)