mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
Merge branch 'master' of https://github.com/duanhf2012/origin
This commit is contained in:
21
Test/.vscode/launch.json
vendored
Normal file
21
Test/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
|
||||
"configurations": [
|
||||
{
|
||||
"name": "N_All",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceRoot}/main.go",
|
||||
"env": {
|
||||
"GOPATH":"${workspaceRoot}/../../../../../"
|
||||
},
|
||||
"args": ["NodeId=1"],
|
||||
"output": "./OriginServer.exe"
|
||||
}
|
||||
]
|
||||
}
|
||||
3
Test/.vscode/settings.json
vendored
Normal file
3
Test/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"go.gopath": "${workspaceRoot}/../../../../../"
|
||||
}
|
||||
@@ -1,25 +1,17 @@
|
||||
{
|
||||
"PublicServiceList":["logiclog"],
|
||||
|
||||
"//":" Auto or Manual",
|
||||
"ClusterPattern":"Auto",
|
||||
"MasterNodeId":1,
|
||||
"NodeList":[
|
||||
{
|
||||
"NodeID":1,
|
||||
"NodeName":"N_Node1",
|
||||
"ServerAddr":"127.0.0.1:8080",
|
||||
|
||||
"ServerAddr":"127.0.0.1:10000",
|
||||
"ServiceList":["CTestService1","CTestService2","HttpServerService","WSServerService","CWebSockService"],
|
||||
"ClusterNode":["N_Node2"]
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
"NodeID":2,
|
||||
"NodeName":"N_Node2",
|
||||
"ServerAddr":"127.0.0.1:8081",
|
||||
"ServiceList":["TestService1","collectTickLogService"],
|
||||
"ClusterNode":[]
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ func (slf *CTestService2) RPC_Add(arg *InputData, ret *int) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
node := originnode.NewOrginNode()
|
||||
node := originnode.NewOriginNode()
|
||||
if node == nil {
|
||||
return
|
||||
}
|
||||
|
||||
10
Test/workspace.code-workspace
Normal file
10
Test/workspace.code-workspace
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"http.systemCertificates": false
|
||||
}
|
||||
}
|
||||
0
doc/教程.docx
Normal file
0
doc/教程.docx
Normal file
@@ -347,9 +347,9 @@ func (client *Client) Call(serviceMethod string, args interface{}, reply interfa
|
||||
select {
|
||||
case call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1), false).Done:
|
||||
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
|
||||
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))
|
||||
}
|
||||
|
||||
@@ -151,7 +151,22 @@ func (slf *BaseModule) releaseModule(moduleId uint32) bool {
|
||||
}
|
||||
|
||||
func (slf *BaseModule) ReleaseModule(moduleId uint32) bool {
|
||||
locker := slf.GetRoot().getBaseModule().getLocker()
|
||||
pRoot := slf.GetRoot()
|
||||
if pRoot == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
baseModule := pRoot.getBaseModule()
|
||||
if baseModule == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
//locker := slf.GetRoot().getBaseModule().getLocker()
|
||||
locker := baseModule.getLocker()
|
||||
if locker == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
locker.Lock()
|
||||
slf.releaseModule(moduleId)
|
||||
locker.Unlock()
|
||||
|
||||
@@ -23,13 +23,13 @@ const (
|
||||
// DBModule ...
|
||||
type DBModule struct {
|
||||
service.BaseModule
|
||||
db *sql.DB
|
||||
url string
|
||||
username string
|
||||
password string
|
||||
dbname string
|
||||
maxconn int
|
||||
PrintTime time.Duration
|
||||
db *sql.DB
|
||||
url string
|
||||
username string
|
||||
password string
|
||||
dbname string
|
||||
maxconn int
|
||||
PrintTime time.Duration
|
||||
syncExecuteFun chan SyncFun
|
||||
syncCoroutineNum int
|
||||
}
|
||||
@@ -241,14 +241,12 @@ func (slf *DBResult) mapSingle2interface(m map[string]string, v reflect.Value) e
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (slf *DBModule) SetQuerySlowTime(Time time.Duration){
|
||||
func (slf *DBModule) SetQuerySlowTime(Time time.Duration) {
|
||||
slf.PrintTime = Time
|
||||
}
|
||||
|
||||
|
||||
func (slf *DBModule) IsPrintTimeLog(Time time.Duration)bool{
|
||||
if slf.PrintTime != 0 && Time >= slf.PrintTime{
|
||||
func (slf *DBModule) IsPrintTimeLog(Time time.Duration) bool {
|
||||
if slf.PrintTime != 0 && Time >= slf.PrintTime {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -337,8 +335,58 @@ func (slf *SyncQueryDBResultEx) Get(timeoutMs int) (*DataSetList, error) {
|
||||
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 ...
|
||||
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 {
|
||||
ret := DBResult{}
|
||||
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.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 {
|
||||
service.GetLogger().Printf(service.LEVER_ERROR, "cannot connect database:%s", query)
|
||||
return &datasetList, fmt.Errorf("cannot connect database!")
|
||||
@@ -372,8 +425,8 @@ func (slf *DBModule) QueryEx(query string, args ...interface{}) (*DataSetList, e
|
||||
rows, err := slf.db.Query(query, args...)
|
||||
TimeFuncPass := time.Since(TimeFuncStart)
|
||||
|
||||
if slf.IsPrintTimeLog(TimeFuncPass) {
|
||||
service.GetLogger().Printf(service.LEVER_INFO, "DBModule QueryEx Time %s , Query :%s , args :%+v",TimeFuncPass,query,args)
|
||||
if slf.IsPrintTimeLog(TimeFuncPass) {
|
||||
service.GetLogger().Printf(service.LEVER_INFO, "DBModule QueryEx Time %s , Query :%s , args :%+v", TimeFuncPass, query, args)
|
||||
}
|
||||
if err != nil {
|
||||
service.GetLogger().Printf(service.LEVER_ERROR, "Query:%s(%v)", query, err)
|
||||
@@ -454,11 +507,17 @@ func (slf *DBModule) Exec(query string, args ...interface{}) (*DBResultEx, error
|
||||
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()
|
||||
res, err := slf.db.Exec(query, args...)
|
||||
TimeFuncPass := time.Since(TimeFuncStart)
|
||||
if slf.IsPrintTimeLog(TimeFuncPass) {
|
||||
service.GetLogger().Printf(service.LEVER_INFO, "DBModule QueryEx Time %s , Query :%s , args :%+v",TimeFuncPass,query,args)
|
||||
service.GetLogger().Printf(service.LEVER_INFO, "DBModule QueryEx Time %s , Query :%s , args :%+v", TimeFuncPass, query, args)
|
||||
}
|
||||
if err != nil {
|
||||
service.GetLogger().Printf(service.LEVER_ERROR, "Exec:%s(%v)", query, err)
|
||||
@@ -514,7 +573,7 @@ func (slf *DBModule) RunExecuteDBCoroutine() {
|
||||
|
||||
func (slf *DataSetList) UnMarshal(args ...interface{}) error {
|
||||
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 {
|
||||
|
||||
@@ -129,6 +129,7 @@ func (slf *HttpServerService) staticServer(w http.ResponseWriter, r *http.Reques
|
||||
w.WriteHeader(status)
|
||||
w.Write([]byte(msg))
|
||||
}
|
||||
|
||||
nowpath, _ := os.Getwd()
|
||||
upath := r.URL.Path
|
||||
destLocalPath := nowpath + upath
|
||||
@@ -145,6 +146,24 @@ func (slf *HttpServerService) staticServer(w http.ResponseWriter, r *http.Reques
|
||||
}
|
||||
//上传资源
|
||||
case "POST":
|
||||
|
||||
// 在这儿处理例外路由接口
|
||||
var errRet error
|
||||
for _, filter := range slf.httpfiltrateList {
|
||||
ret := filter(r.URL.Path, w, r)
|
||||
if ret == nil {
|
||||
errRet = nil
|
||||
break
|
||||
} else {
|
||||
errRet = ret
|
||||
}
|
||||
}
|
||||
|
||||
if errRet != nil {
|
||||
w.Write([]byte(errRet.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
r.ParseMultipartForm(32 << 20) // max memory is set to 32MB
|
||||
resourceFile, resourceFileHeader, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
@@ -172,7 +191,8 @@ func (slf *HttpServerService) staticServer(w http.ResponseWriter, r *http.Reques
|
||||
defer localfd.Close()
|
||||
|
||||
io.Copy(localfd, resourceFile)
|
||||
writeResp(http.StatusOK, localpath)
|
||||
|
||||
writeResp(http.StatusOK, upath+fileName)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -187,6 +207,10 @@ func (slf *HttpServerService) httpHandler(w http.ResponseWriter, r *http.Request
|
||||
//writeError(http.StatusMethodNotAllowed, "rpc: POST method required, received "+r.Method)
|
||||
//return
|
||||
}
|
||||
if r.Method == "OPTIONS" {
|
||||
return
|
||||
}
|
||||
|
||||
defer r.Body.Close()
|
||||
msg, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user