mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-19 05:28:07 +01:00
♻️ Refactor Go to err != nil, err == nil (#12385)
This commit is contained in:
parent
473a159ef2
commit
b100721fee
147 changed files with 1661 additions and 1659 deletions
|
|
@ -55,7 +55,7 @@ func listDocTree(c *gin.Context) {
|
|||
var doctree []*DocFile
|
||||
root := filepath.Join(util.WorkspaceDir, "data", notebook, p)
|
||||
dir, err := os.ReadDir(root)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -77,7 +77,7 @@ func listDocTree(c *gin.Context) {
|
|||
doctree = append(doctree, parent)
|
||||
|
||||
subPath := filepath.Join(root, entry.Name())
|
||||
if err = walkDocTree(subPath, parent, &ids); nil != err {
|
||||
if err = walkDocTree(subPath, parent, &ids); err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -103,7 +103,7 @@ type DocFile struct {
|
|||
|
||||
func walkDocTree(p string, docFile *DocFile, ids *map[string]bool) (err error) {
|
||||
dir, err := os.ReadDir(p)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ func walkDocTree(p string, docFile *DocFile, ids *map[string]bool) (err error) {
|
|||
docFile.Children = append(docFile.Children, parent)
|
||||
|
||||
subPath := filepath.Join(p, entry.Name())
|
||||
if err = walkDocTree(subPath, parent, ids); nil != err {
|
||||
if err = walkDocTree(subPath, parent, ids); err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
|
@ -190,7 +190,7 @@ func doc2Heading(c *gin.Context) {
|
|||
targetID := arg["targetID"].(string)
|
||||
after := arg["after"].(bool)
|
||||
srcTreeBox, srcTreePath, err := model.Doc2Heading(srcID, targetID, after)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
||||
|
|
@ -216,7 +216,7 @@ func heading2Doc(c *gin.Context) {
|
|||
targetNotebook := arg["targetNoteBook"].(string)
|
||||
targetPath := arg["targetPath"].(string)
|
||||
srcRootBlockID, targetPath, err := model.Heading2Doc(srcHeadingID, targetNotebook, targetPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
||||
|
|
@ -226,7 +226,7 @@ func heading2Doc(c *gin.Context) {
|
|||
model.WaitForWritingFiles()
|
||||
luteEngine := util.NewLute()
|
||||
tree, err := filesys.LoadTree(targetNotebook, targetPath, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -261,7 +261,7 @@ func li2Doc(c *gin.Context) {
|
|||
targetNotebook := arg["targetNoteBook"].(string)
|
||||
targetPath := arg["targetPath"].(string)
|
||||
srcRootBlockID, targetPath, err := model.ListItem2Doc(srcListItemID, targetNotebook, targetPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
||||
|
|
@ -271,7 +271,7 @@ func li2Doc(c *gin.Context) {
|
|||
model.WaitForWritingFiles()
|
||||
luteEngine := util.NewLute()
|
||||
tree, err := filesys.LoadTree(targetNotebook, targetPath, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -310,7 +310,7 @@ func getHPathByPath(c *gin.Context) {
|
|||
p := arg["path"].(string)
|
||||
|
||||
hPath, err := model.GetHPathByPath(notebook, p)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -333,7 +333,7 @@ func getHPathsByPaths(c *gin.Context) {
|
|||
paths = append(paths, p.(string))
|
||||
}
|
||||
hPath, err := model.GetHPathsByPaths(paths)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -356,7 +356,7 @@ func getHPathByID(c *gin.Context) {
|
|||
}
|
||||
|
||||
hPath, err := model.GetHPathByID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -379,7 +379,7 @@ func getPathByID(c *gin.Context) {
|
|||
}
|
||||
|
||||
_path, err := model.GetPathByID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -401,7 +401,7 @@ func getFullHPathByID(c *gin.Context) {
|
|||
|
||||
id := arg["id"].(string)
|
||||
hPath, err := model.GetFullHPathByID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -431,7 +431,7 @@ func getIDsByHPath(c *gin.Context) {
|
|||
|
||||
p := arg["path"].(string)
|
||||
ids, err := model.GetIDsByHPath(p, notebook)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -462,7 +462,7 @@ func moveDocs(c *gin.Context) {
|
|||
callback := arg["callback"]
|
||||
|
||||
err := model.MoveDocs(fromPaths, toNotebook, toPath, callback)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 7000}
|
||||
|
|
@ -523,7 +523,7 @@ func renameDoc(c *gin.Context) {
|
|||
title := arg["title"].(string)
|
||||
|
||||
err := model.RenameDoc(notebook, p, title)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -542,7 +542,7 @@ func duplicateDoc(c *gin.Context) {
|
|||
|
||||
id := arg["id"].(string)
|
||||
tree, err := model.LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 7000}
|
||||
|
|
@ -584,7 +584,7 @@ func createDoc(c *gin.Context) {
|
|||
}
|
||||
|
||||
tree, err := model.CreateDocByMd(notebook, p, title, md, sorts)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 7000}
|
||||
|
|
@ -611,7 +611,7 @@ func createDailyNote(c *gin.Context) {
|
|||
|
||||
notebook := arg["notebook"].(string)
|
||||
p, existed, err := model.CreateDailyNote(notebook)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
if model.ErrBoxNotFound == err {
|
||||
ret.Code = 1
|
||||
} else {
|
||||
|
|
@ -625,7 +625,7 @@ func createDailyNote(c *gin.Context) {
|
|||
box := model.Conf.Box(notebook)
|
||||
luteEngine := util.NewLute()
|
||||
tree, err := filesys.LoadTree(box.ID, p, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -707,7 +707,7 @@ func createDocWithMd(c *gin.Context) {
|
|||
}
|
||||
|
||||
id, err := model.CreateWithMarkdown(notebook, hPath, markdown, parentID, id, withMath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -764,7 +764,7 @@ func getDocCreateSavePath(c *gin.Context) {
|
|||
}
|
||||
|
||||
docCreateSavePath, err := model.RenderGoTemplate(docCreateSavePathTpl)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -818,7 +818,7 @@ func getRefCreateSavePath(c *gin.Context) {
|
|||
}
|
||||
|
||||
refCreateSavePath, err := model.RenderGoTemplate(refCreateSavePathTpl)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -899,7 +899,7 @@ func listDocsByPath(c *gin.Context) {
|
|||
}
|
||||
|
||||
files, totals, err := model.ListDocTree(notebook, p, sortMode, flashcard, showHidden, maxListCount)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -983,7 +983,7 @@ func getDoc(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = 1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue