|
@@ -10,6 +10,7 @@ import ( |
|
|
"fmt" |
|
|
"fmt" |
|
|
"fts/config" |
|
|
"fts/config" |
|
|
"fts/etcdclient" |
|
|
"fts/etcdclient" |
|
|
|
|
|
"fts/nsqclient" |
|
|
"github.com/gorilla/websocket" |
|
|
"github.com/gorilla/websocket" |
|
|
_ "github.com/ipfs/go-ipfs-api" |
|
|
_ "github.com/ipfs/go-ipfs-api" |
|
|
shell "github.com/ipfs/go-ipfs-api" |
|
|
shell "github.com/ipfs/go-ipfs-api" |
|
@@ -61,6 +62,7 @@ type processStruct struct { |
|
|
Process float64 `json:"process"` |
|
|
Process float64 `json:"process"` |
|
|
Hash string `json:"hash"` |
|
|
Hash string `json:"hash"` |
|
|
CommitHistoryHash string `json:"commitHistoryHash"` |
|
|
CommitHistoryHash string `json:"commitHistoryHash"` |
|
|
|
|
|
Version int `json:"version"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -163,6 +165,19 @@ func DownCommand(conn *websocket.Conn, hash, projectName, fileName, nodeDir stri |
|
|
//下载启动标识,有下载进度则设置为true |
|
|
//下载启动标识,有下载进度则设置为true |
|
|
var downloading bool = false |
|
|
var downloading bool = false |
|
|
|
|
|
|
|
|
|
|
|
//检测文件打开状态 |
|
|
|
|
|
tfile,err := os.OpenFile(fmt.Sprint(fileDir+"\\"+fileName),os.O_RDWR,1) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil && (!os.IsNotExist(err)) { |
|
|
|
|
|
|
|
|
|
|
|
log.Println("文件被占用,请关闭打开的软件") |
|
|
|
|
|
if err := conn.WriteMessage(websocket.TextMessage, []byte("-2")); err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
defer tfile.Close() |
|
|
|
|
|
|
|
|
//正在下载标识,标识用于不监测更新改动 |
|
|
//正在下载标识,标识用于不监测更新改动 |
|
|
gobalFileDownLoadingMap[fmt.Sprint(fileDir+"\\"+fileName)]=1 |
|
|
gobalFileDownLoadingMap[fmt.Sprint(fileDir+"\\"+fileName)]=1 |
|
|
|
|
|
|
|
@@ -186,6 +201,7 @@ func DownCommand(conn *websocket.Conn, hash, projectName, fileName, nodeDir stri |
|
|
go func(){ |
|
|
go func(){ |
|
|
millSeconds := time.Now().UnixNano() / 1e6 |
|
|
millSeconds := time.Now().UnixNano() / 1e6 |
|
|
for content := range progress { // 通道关闭后会退出for range循环 |
|
|
for content := range progress { // 通道关闭后会退出for range循环 |
|
|
|
|
|
log.Println(">>>"+content) |
|
|
current :=time.Now().UnixNano() / 1e6 |
|
|
current :=time.Now().UnixNano() / 1e6 |
|
|
if !downloading{ |
|
|
if !downloading{ |
|
|
log.Println("资源连接成功,下载中...") |
|
|
log.Println("资源连接成功,下载中...") |
|
@@ -220,7 +236,7 @@ func DownCommand(conn *websocket.Conn, hash, projectName, fileName, nodeDir stri |
|
|
log.Printf("json.Marshal error %s\n", err) |
|
|
log.Printf("json.Marshal error %s\n", err) |
|
|
} |
|
|
} |
|
|
if err := conn.WriteMessage(websocket.TextMessage, projson); err != nil { |
|
|
if err := conn.WriteMessage(websocket.TextMessage, projson); err != nil { |
|
|
panic(err) |
|
|
|
|
|
|
|
|
log.Println(err) |
|
|
} |
|
|
} |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
@@ -263,7 +279,7 @@ func DownCommand(conn *websocket.Conn, hash, projectName, fileName, nodeDir stri |
|
|
//更新Etcd数据库的文件key对应hash值 |
|
|
//更新Etcd数据库的文件key对应hash值 |
|
|
time.Sleep(200*time.Millisecond) |
|
|
time.Sleep(200*time.Millisecond) |
|
|
key := gobalLoginUserName+"\\"+projectName+"\\"+nodeDir+"\\"+fileName |
|
|
key := gobalLoginUserName+"\\"+projectName+"\\"+nodeDir+"\\"+fileName |
|
|
err = etcdclient.ReplaceInto(key,hash) |
|
|
|
|
|
|
|
|
err = etcdclient.ReplaceInto(key,hash+";0") |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Println(err) |
|
|
log.Println(err) |
|
|
return err |
|
|
return err |
|
@@ -272,6 +288,9 @@ func DownCommand(conn *websocket.Conn, hash, projectName, fileName, nodeDir stri |
|
|
//发送消息至文件变更订阅 |
|
|
//发送消息至文件变更订阅 |
|
|
config.GobalWatchChannelMap[config.LocalWorkSpaceDir+gobalLoginUserName+"\\"+projectName] <- ";" |
|
|
config.GobalWatchChannelMap[config.LocalWorkSpaceDir+gobalLoginUserName+"\\"+projectName] <- ";" |
|
|
|
|
|
|
|
|
|
|
|
//下载完成反馈 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.Printf("叮,资源文件[ %v ]下载完成",fileName) |
|
|
log.Printf("叮,资源文件[ %v ]下载完成",fileName) |
|
|
defer time.Sleep(5*time.Second);gobalFileDownLoadingMap[fmt.Sprint(fileDir+"\\"+fileName)]=0 |
|
|
defer time.Sleep(5*time.Second);gobalFileDownLoadingMap[fmt.Sprint(fileDir+"\\"+fileName)]=0 |
|
|
defer close(progress) |
|
|
defer close(progress) |
|
@@ -336,6 +355,17 @@ func UploadCommand(conn *websocket.Conn,absolutePath,fileName,projectName,dir,cu |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//检测文件打开状态 |
|
|
|
|
|
tfile,err := os.OpenFile(absolutePath,os.O_RDWR,1) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println("文件被占用,请关闭打开的软件") |
|
|
|
|
|
if err := conn.WriteMessage(websocket.TextMessage, []byte("-2")); err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
defer tfile.Close() |
|
|
|
|
|
|
|
|
serverSh := shell.NewShell(config.ServerIpfsUrl) |
|
|
serverSh := shell.NewShell(config.ServerIpfsUrl) |
|
|
//serverSh.SetTimeout(time.Duration(30)*time.Second) |
|
|
//serverSh.SetTimeout(time.Duration(30)*time.Second) |
|
|
//log.Println("检测引导节点存活情况"+config.ServerIpfsUrl) |
|
|
//log.Println("检测引导节点存活情况"+config.ServerIpfsUrl) |
|
@@ -566,6 +596,7 @@ func UploadCommand(conn *websocket.Conn,absolutePath,fileName,projectName,dir,cu |
|
|
prog.Process=100.00 |
|
|
prog.Process=100.00 |
|
|
prog.Size=strconv.Itoa(objectStat.CumulativeSize) |
|
|
prog.Size=strconv.Itoa(objectStat.CumulativeSize) |
|
|
prog.CommitHistoryHash=commitHistoryHash |
|
|
prog.CommitHistoryHash=commitHistoryHash |
|
|
|
|
|
prog.Version=commitVersion |
|
|
projson,err :=json.Marshal(prog) |
|
|
projson,err :=json.Marshal(prog) |
|
|
|
|
|
|
|
|
if conn!=nil{ |
|
|
if conn!=nil{ |
|
@@ -583,20 +614,21 @@ func UploadCommand(conn *websocket.Conn,absolutePath,fileName,projectName,dir,cu |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if conn==nil{ |
|
|
|
|
|
folderName := strings.Split(dir,"\\")[0] |
|
|
|
|
|
var relativePath string |
|
|
|
|
|
if len(strings.Split(dir, "\\"))==1{ |
|
|
|
|
|
relativePath = "" |
|
|
|
|
|
}else{ |
|
|
|
|
|
relativePath = strings.Replace(relativePath, folderName+"\\","",1) |
|
|
|
|
|
} |
|
|
|
|
|
size,_ := strconv.ParseInt(prog.Size,10,64) |
|
|
|
|
|
err = postUpdateFile(projectName,folderName,relativePath,fileHash, fileName, commitHistoryHash, currentHistoryHash, gobalLoginUserId, size, commitVersion) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//自动协同逻辑 |
|
|
|
|
|
//if conn==nil{ |
|
|
|
|
|
// folderName := strings.Split(dir,"\\")[0] |
|
|
|
|
|
// var relativePath string |
|
|
|
|
|
// if len(strings.Split(dir, "\\"))==1{ |
|
|
|
|
|
// relativePath = "" |
|
|
|
|
|
// }else{ |
|
|
|
|
|
// relativePath = strings.Replace(relativePath, folderName+"\\","",1) |
|
|
|
|
|
// } |
|
|
|
|
|
// size,_ := strconv.ParseInt(prog.Size,10,64) |
|
|
|
|
|
// err = postUpdateFile(projectName,folderName,relativePath,fileHash, fileName, commitHistoryHash, currentHistoryHash, gobalLoginUserId, size, commitVersion) |
|
|
|
|
|
// if err!=nil{ |
|
|
|
|
|
// return err |
|
|
|
|
|
// } |
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
//发送文件至文件变更订阅 |
|
|
//发送文件至文件变更订阅 |
|
|
config.GobalWatchChannelMap[config.LocalWorkSpaceDir+gobalLoginUserName+"\\"+projectName] <- ";" |
|
|
config.GobalWatchChannelMap[config.LocalWorkSpaceDir+gobalLoginUserName+"\\"+projectName] <- ";" |
|
@@ -792,6 +824,9 @@ func commitRecord(path,currentHistoryHash,hash,note,creator string, milestone bo |
|
|
commitHistory.CreateTime=time.Now().Unix() |
|
|
commitHistory.CreateTime=time.Now().Unix() |
|
|
|
|
|
|
|
|
if commitHistory.ParentHash==commitHistory.CurrentHash{ |
|
|
if commitHistory.ParentHash==commitHistory.CurrentHash{ |
|
|
|
|
|
if commitHistory.Version>1{ |
|
|
|
|
|
commitHistory.Version-- |
|
|
|
|
|
} |
|
|
return commitHistory.Version,currentHistoryHash,nil |
|
|
return commitHistory.Version,currentHistoryHash,nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -1089,42 +1124,41 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
} |
|
|
} |
|
|
log.Printf("文件变更 [ %v ] write", actionAndModifyFilePathStr) |
|
|
log.Printf("文件变更 [ %v ] write", actionAndModifyFilePathStr) |
|
|
|
|
|
|
|
|
//如果非新增文件则自动post |
|
|
|
|
|
filePath := actionAndModifyFilePath[1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//保存即同步逻辑,如果非新增文件则自动post |
|
|
//获取文件的历史版本管理文件hash |
|
|
//获取文件的历史版本管理文件hash |
|
|
fileName :=filepath.Base(filePath) |
|
|
|
|
|
folderName := strings.Split(queryKey,"\\")[2] |
|
|
|
|
|
dir := strings.Replace(strings.Replace(queryKey,"\\"+fileName,"",1),strings.Split(queryKey,"\\")[0]+"\\"+strings.Split(queryKey,"\\")[1]+"\\","",1) |
|
|
|
|
|
var relativePath string |
|
|
|
|
|
if len(strings.Split(dir, "\\"))==1{ |
|
|
|
|
|
relativePath = "" |
|
|
|
|
|
}else{ |
|
|
|
|
|
relativePath = strings.Replace(relativePath, folderName+"\\","",1) |
|
|
|
|
|
} |
|
|
|
|
|
historyCurrentHash,err :=postGetHistoryCurrentHash(projectName, folderName, fileName, relativePath) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
GobalMessageNotify <- fmt.Sprintf("文件更新失败\n%v",fileName) |
|
|
|
|
|
log.Printf("postGetHistoryCurrentHash 返回失败,%v",err.Error()) |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//自动更新文件 |
|
|
|
|
|
err =UploadCommand(nil,filePath,fileName,projectName,dir,historyCurrentHash,"",gobalLoginUserName,false) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
GobalMessageNotify <- fmt.Sprintf("文件更新失败\n%v",fileName) |
|
|
|
|
|
log.Printf("UploadCommand 返回失败,%v",err.Error()) |
|
|
|
|
|
//记录修改状态 |
|
|
|
|
|
newValue := oldValue[0]+";" +"1" |
|
|
|
|
|
err = etcdclient.ReplaceInto(queryKey,newValue) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
GobalMessageNotify <- fmt.Sprintf("文件更新成功\n%v",fileName) |
|
|
|
|
|
continue |
|
|
|
|
|
|
|
|
//filePath := actionAndModifyFilePath[1] |
|
|
|
|
|
//fileName :=filepath.Base(filePath) |
|
|
|
|
|
//folderName := strings.Split(queryKey,"\\")[2] |
|
|
|
|
|
//dir := strings.Replace(strings.Replace(queryKey,"\\"+fileName,"",1),strings.Split(queryKey,"\\")[0]+"\\"+strings.Split(queryKey,"\\")[1]+"\\","",1) |
|
|
|
|
|
//var relativePath string |
|
|
|
|
|
//if len(strings.Split(dir, "\\"))==1{ |
|
|
|
|
|
// relativePath = "" |
|
|
|
|
|
//}else{ |
|
|
|
|
|
// relativePath = strings.Replace(relativePath, folderName+"\\","",1) |
|
|
|
|
|
//} |
|
|
|
|
|
//historyCurrentHash,err :=postGetHistoryCurrentHash(projectName, folderName, fileName, relativePath) |
|
|
|
|
|
//if err!=nil{ |
|
|
|
|
|
// GobalMessageNotify <- fmt.Sprintf("文件更新失败\n%v",fileName) |
|
|
|
|
|
// log.Printf("postGetHistoryCurrentHash 返回失败,%v",err.Error()) |
|
|
|
|
|
// continue |
|
|
|
|
|
//} |
|
|
|
|
|
// |
|
|
|
|
|
////自动更新文件 |
|
|
|
|
|
//err =UploadCommand(nil,filePath,fileName,projectName,dir,historyCurrentHash,"",gobalLoginUserName,false) |
|
|
|
|
|
//if err!=nil{ |
|
|
|
|
|
// GobalMessageNotify <- fmt.Sprintf("文件更新失败\n%v",fileName) |
|
|
|
|
|
// log.Printf("UploadCommand 返回失败,%v",err.Error()) |
|
|
|
|
|
// //记录修改状态 |
|
|
|
|
|
// newValue := oldValue[0]+";" +"1" |
|
|
|
|
|
// err = etcdclient.ReplaceInto(queryKey,newValue) |
|
|
|
|
|
// if err!=nil{ |
|
|
|
|
|
// log.Println(err) |
|
|
|
|
|
// continue |
|
|
|
|
|
// } |
|
|
|
|
|
// continue |
|
|
|
|
|
//} |
|
|
|
|
|
//GobalMessageNotify <- fmt.Sprintf("文件更新成功\n%v",fileName) |
|
|
|
|
|
//continue |
|
|
}else if actionAndModifyFilePath[0]=="create"{ |
|
|
}else if actionAndModifyFilePath[0]=="create"{ |
|
|
querymap,err := etcdclient.QueryWithPrefix(queryKey) |
|
|
querymap,err := etcdclient.QueryWithPrefix(queryKey) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@@ -1134,6 +1168,7 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
if len(querymap)==0{ |
|
|
if len(querymap)==0{ |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//更新判断 |
|
|
//更新判断 |
|
|
if gobalFileDownLoadingMap[actionAndModifyFilePath[1]]==1{ |
|
|
if gobalFileDownLoadingMap[actionAndModifyFilePath[1]]==1{ |
|
|
continue |
|
|
continue |
|
@@ -1150,41 +1185,40 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
|
|
|
|
|
|
//如果非新增文件则自动post |
|
|
//如果非新增文件则自动post |
|
|
//if goabalAddFileMap[] |
|
|
//if goabalAddFileMap[] |
|
|
filePath := actionAndModifyFilePath[1] |
|
|
|
|
|
|
|
|
|
|
|
//获取文件的历史版本管理文件hash |
|
|
//获取文件的历史版本管理文件hash |
|
|
fileName :=filepath.Base(filePath) |
|
|
|
|
|
folderName := strings.Split(queryKey,"\\")[2] |
|
|
|
|
|
dir := strings.Replace(strings.Replace(queryKey,"\\"+fileName,"",1),strings.Split(queryKey,"\\")[0]+"\\"+strings.Split(queryKey,"\\")[1]+"\\","",1) |
|
|
|
|
|
var relativePath string |
|
|
|
|
|
if len(strings.Split(dir, "\\"))==1{ |
|
|
|
|
|
relativePath = "" |
|
|
|
|
|
}else{ |
|
|
|
|
|
relativePath = strings.Replace(relativePath, folderName+"\\","",1) |
|
|
|
|
|
} |
|
|
|
|
|
historyCurrentHash,err :=postGetHistoryCurrentHash(projectName, folderName, fileName, relativePath) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
GobalMessageNotify <- fmt.Sprintf("文件更新失败\n%v",fileName) |
|
|
|
|
|
log.Printf("postGetHistoryCurrentHash 返回失败,%v",err.Error()) |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//自动更新文件 |
|
|
|
|
|
err =UploadCommand(nil,filePath,fileName,projectName,dir,historyCurrentHash,"",gobalLoginUserName,false) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
GobalMessageNotify <- fmt.Sprintf("文件更新失败\n%v",fileName) |
|
|
|
|
|
log.Printf("UploadCommand 返回失败,%v",err.Error()) |
|
|
|
|
|
//记录修改状态 |
|
|
|
|
|
newValue := oldValue[0]+";" +"1" |
|
|
|
|
|
err = etcdclient.ReplaceInto(queryKey,newValue) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
GobalMessageNotify <- fmt.Sprintf("文件更新成功\n%v",fileName) |
|
|
|
|
|
continue |
|
|
|
|
|
|
|
|
//filePath := actionAndModifyFilePath[1] |
|
|
|
|
|
//fileName :=filepath.Base(filePath) |
|
|
|
|
|
//folderName := strings.Split(queryKey,"\\")[2] |
|
|
|
|
|
//dir := strings.Replace(strings.Replace(queryKey,"\\"+fileName,"",1),strings.Split(queryKey,"\\")[0]+"\\"+strings.Split(queryKey,"\\")[1]+"\\","",1) |
|
|
|
|
|
//var relativePath string |
|
|
|
|
|
//if len(strings.Split(dir, "\\"))==1{ |
|
|
|
|
|
// relativePath = "" |
|
|
|
|
|
//}else{ |
|
|
|
|
|
// relativePath = strings.Replace(relativePath, folderName+"\\","",1) |
|
|
|
|
|
//} |
|
|
|
|
|
//historyCurrentHash,err :=postGetHistoryCurrentHash(projectName, folderName, fileName, relativePath) |
|
|
|
|
|
//if err!=nil{ |
|
|
|
|
|
// GobalMessageNotify <- fmt.Sprintf("文件更新失败\n%v",fileName) |
|
|
|
|
|
// log.Printf("postGetHistoryCurrentHash 返回失败,%v",err.Error()) |
|
|
|
|
|
// continue |
|
|
|
|
|
//} |
|
|
|
|
|
// |
|
|
|
|
|
////自动更新文件 |
|
|
|
|
|
//err =UploadCommand(nil,filePath,fileName,projectName,dir,historyCurrentHash,"",gobalLoginUserName,false) |
|
|
|
|
|
//if err!=nil{ |
|
|
|
|
|
// GobalMessageNotify <- fmt.Sprintf("文件更新失败\n%v",fileName) |
|
|
|
|
|
// log.Printf("UploadCommand 返回失败,%v",err.Error()) |
|
|
|
|
|
// //记录修改状态 |
|
|
|
|
|
// newValue := oldValue[0]+";" +"1" |
|
|
|
|
|
// err = etcdclient.ReplaceInto(queryKey,newValue) |
|
|
|
|
|
// if err!=nil{ |
|
|
|
|
|
// log.Println(err) |
|
|
|
|
|
// continue |
|
|
|
|
|
// } |
|
|
|
|
|
// continue |
|
|
|
|
|
//} |
|
|
|
|
|
//GobalMessageNotify <- fmt.Sprintf("文件更新成功\n%v",fileName) |
|
|
|
|
|
//continue |
|
|
} |
|
|
} |
|
|
err = sendFileListFromEtcd(keyPrefix,projectName,conn) |
|
|
err = sendFileListFromEtcd(keyPrefix,projectName,conn) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@@ -1514,6 +1548,87 @@ type commitHistory struct { |
|
|
Milestone bool `json:"milestone"` |
|
|
Milestone bool `json:"milestone"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
消息通知 |
|
|
|
|
|
@param userId 用户ID |
|
|
|
|
|
*/ |
|
|
|
|
|
func MessageNotify(conn *websocket.Conn, userId string) (error){ |
|
|
|
|
|
msgKey :=fmt.Sprintf("lockingMsg\\%v",userId) |
|
|
|
|
|
|
|
|
|
|
|
//返回全量通知消息列表 |
|
|
|
|
|
err :=queryEtcdToWebSocket(conn, msgKey) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//消费通知消息到本地 |
|
|
|
|
|
nsqclient.Consumers(config.NsqTopic,(config.NsqChanelPrefix+userId),config.NsqAddr) |
|
|
|
|
|
|
|
|
|
|
|
for message := range nsqclient.MsgQueue { |
|
|
|
|
|
messOb :=nsqclient.LockingMsg{} |
|
|
|
|
|
err:=json.Unmarshal([]byte(message),&messOb) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, acceptUserId := range messOb.UserIds { |
|
|
|
|
|
//log.Println(strconv.FormatInt(acceptUserId,10)+">>>"+userId) |
|
|
|
|
|
if strconv.FormatInt(acceptUserId,10)==userId{ |
|
|
|
|
|
messagekey := msgKey+"\\"+strconv.FormatInt(messOb.Id,10) |
|
|
|
|
|
err =etcdclient.ReplaceInto(messagekey,message) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
nsqclient.MsgQueue <- message |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
err = queryEtcdToWebSocket(conn, messagekey) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
nsqclient.MsgQueue <- message |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
消息通知 |
|
|
|
|
|
@param userId 用户ID |
|
|
|
|
|
*/ |
|
|
|
|
|
func MessageMarkReadHandler(conn *websocket.Conn, userId,messageId string) (err error){ |
|
|
|
|
|
msgKey :=fmt.Sprintf("lockingMsg\\%v\\%v",userId,messageId) |
|
|
|
|
|
err = etcdclient.DeleteWithPrefix(msgKey) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
查询etcd对应key值发送给前端 |
|
|
|
|
|
*/ |
|
|
|
|
|
func queryEtcdToWebSocket(conn *websocket.Conn,etcdKeyPrefix string) (err error){ |
|
|
|
|
|
msgs,err := etcdclient.QueryWithPrefix(etcdKeyPrefix) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
mapByte,err :=json.Marshal(msgs) |
|
|
|
|
|
if err!=nil{ |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
return err |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := conn.WriteMessage(websocket.TextMessage, mapByte); err != nil { |
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
return err |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|