This commit is contained in:
Haki
2019-07-30 10:13:45 +08:00
2 changed files with 77 additions and 18 deletions

View File

@@ -347,9 +347,9 @@ func (client *Client) Call(serviceMethod string, args interface{}, reply interfa
select { select {
case call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1), false).Done: case call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1), false).Done:
return call.Error return call.Error
case <-time.After(15 * time.Second): case <-time.After(30 * time.Second):
} }
//call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1)).Done //call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1)).Done
return errors.New(fmt.Sprintf("Call RPC %s is time out 10s", serviceMethod)) return errors.New(fmt.Sprintf("Call RPC %s is time out 30s", serviceMethod))
} }

View File

@@ -241,12 +241,10 @@ func (slf *DBResult) mapSingle2interface(m map[string]string, v reflect.Value) e
return nil return nil
} }
func (slf *DBModule) SetQuerySlowTime(Time time.Duration) { func (slf *DBModule) SetQuerySlowTime(Time time.Duration) {
slf.PrintTime = Time slf.PrintTime = Time
} }
func (slf *DBModule) IsPrintTimeLog(Time time.Duration) bool { func (slf *DBModule) IsPrintTimeLog(Time time.Duration) bool {
if slf.PrintTime != 0 && Time >= slf.PrintTime { if slf.PrintTime != 0 && Time >= slf.PrintTime {
return true return true
@@ -337,8 +335,58 @@ func (slf *SyncQueryDBResultEx) Get(timeoutMs int) (*DataSetList, error) {
return nil, fmt.Errorf("Getting the return result timeout [%d]ms", timeoutMs) return nil, fmt.Errorf("Getting the return result timeout [%d]ms", timeoutMs)
} }
func (slf *DBModule) CheckArgs(args ...interface{}) error {
for _, val := range args {
if reflect.TypeOf(val).Kind() == reflect.String {
retVal := val.(string)
if strings.Contains(retVal, "-") == true {
return fmt.Errorf("CheckArgs is error arg is %+v", retVal)
}
if strings.Contains(retVal, "#") == true {
return fmt.Errorf("CheckArgs is error arg is %+v", retVal)
}
if strings.Contains(retVal, "&") == true {
return fmt.Errorf("CheckArgs is error arg is %+v", retVal)
}
if strings.Contains(retVal, "=") == true {
return fmt.Errorf("CheckArgs is error arg is %+v", retVal)
}
if strings.Contains(retVal, "%") == true {
return fmt.Errorf("CheckArgs is error arg is %+v", retVal)
}
if strings.Contains(retVal, "'") == true {
return fmt.Errorf("CheckArgs is error arg is %+v", retVal)
}
if strings.Contains(strings.ToLower(retVal), "delete ") == true {
return fmt.Errorf("CheckArgs is error arg is %+v", retVal)
}
if strings.Contains(strings.ToLower(retVal), "truncate ") == true {
return fmt.Errorf("CheckArgs is error arg is %+v", retVal)
}
if strings.Contains(strings.ToLower(retVal), " or ") == true {
return fmt.Errorf("CheckArgs is error arg is %+v", retVal)
}
if strings.Contains(strings.ToLower(retVal), "from ") == true {
return fmt.Errorf("CheckArgs is error arg is %+v", retVal)
}
if strings.Contains(strings.ToLower(retVal), "set ") == true {
return fmt.Errorf("CheckArgs is error arg is %+v", retVal)
}
}
}
return nil
}
// Query ... // Query ...
func (slf *DBModule) Query(query string, args ...interface{}) DBResult { func (slf *DBModule) Query(query string, args ...interface{}) DBResult {
if slf.CheckArgs(args) != nil {
ret := DBResult{}
service.GetLogger().Printf(service.LEVER_ERROR, "CheckArgs is error :%s", query)
ret.Err = fmt.Errorf("CheckArgs is error!")
return ret
}
if slf.db == nil { if slf.db == nil {
ret := DBResult{} ret := DBResult{}
service.GetLogger().Printf(service.LEVER_ERROR, "cannot connect database:%s", query) service.GetLogger().Printf(service.LEVER_ERROR, "cannot connect database:%s", query)
@@ -363,6 +411,11 @@ func (slf *DBModule) QueryEx(query string, args ...interface{}) (*DataSetList, e
datasetList.tag = "json" datasetList.tag = "json"
datasetList.blur = true datasetList.blur = true
if slf.CheckArgs(args) != nil {
service.GetLogger().Printf(service.LEVER_ERROR, "CheckArgs is error :%s", query)
return &datasetList, fmt.Errorf("CheckArgs is error!")
}
if slf.db == nil { if slf.db == nil {
service.GetLogger().Printf(service.LEVER_ERROR, "cannot connect database:%s", query) service.GetLogger().Printf(service.LEVER_ERROR, "cannot connect database:%s", query)
return &datasetList, fmt.Errorf("cannot connect database!") return &datasetList, fmt.Errorf("cannot connect database!")
@@ -454,6 +507,12 @@ func (slf *DBModule) Exec(query string, args ...interface{}) (*DBResultEx, error
return ret, fmt.Errorf("cannot connect database!") return ret, fmt.Errorf("cannot connect database!")
} }
if slf.CheckArgs(args) != nil {
service.GetLogger().Printf(service.LEVER_ERROR, "CheckArgs is error :%s", query)
//return ret, fmt.Errorf("cannot connect database!")
return ret, fmt.Errorf("CheckArgs is error!")
}
TimeFuncStart := time.Now() TimeFuncStart := time.Now()
res, err := slf.db.Exec(query, args...) res, err := slf.db.Exec(query, args...)
TimeFuncPass := time.Since(TimeFuncStart) TimeFuncPass := time.Since(TimeFuncStart)
@@ -514,7 +573,7 @@ func (slf *DBModule) RunExecuteDBCoroutine() {
func (slf *DataSetList) UnMarshal(args ...interface{}) error { func (slf *DataSetList) UnMarshal(args ...interface{}) error {
if len(slf.dataSetList) != len(args) { if len(slf.dataSetList) != len(args) {
return errors.New("Data set len(%d) is not equal to args!") return errors.New(fmt.Sprintf("Data set len(%d,%d) is not equal to args!", len(slf.dataSetList), len(args)))
} }
for _, out := range args { for _, out := range args {