mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-29 21:08:49 +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
|
|
@ -57,7 +57,7 @@ func checkWorkspaceDir(c *gin.Context) {
|
|||
}
|
||||
|
||||
entries, err := os.ReadDir(path)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = fmt.Sprintf("read workspace dir [%s] failed: %s", path, err)
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ func createWorkspaceDir(c *gin.Context) {
|
|||
}
|
||||
|
||||
if !gulu.File.IsExist(absPath) {
|
||||
if err := os.MkdirAll(absPath, 0755); nil != err {
|
||||
if err := os.MkdirAll(absPath, 0755); err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = fmt.Sprintf("create workspace dir [%s] failed: %s", absPath, err)
|
||||
return
|
||||
|
|
@ -112,7 +112,7 @@ func createWorkspaceDir(c *gin.Context) {
|
|||
}
|
||||
|
||||
workspacePaths, err := util.ReadWorkspacePaths()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -120,7 +120,7 @@ func createWorkspaceDir(c *gin.Context) {
|
|||
|
||||
workspacePaths = append(workspacePaths, absPath)
|
||||
|
||||
if err = util.WriteWorkspacePaths(workspacePaths); nil != err {
|
||||
if err = util.WriteWorkspacePaths(workspacePaths); err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -147,7 +147,7 @@ func removeWorkspaceDir(c *gin.Context) {
|
|||
}
|
||||
|
||||
workspacePaths, err := util.ReadWorkspacePaths()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -155,7 +155,7 @@ func removeWorkspaceDir(c *gin.Context) {
|
|||
|
||||
workspacePaths = gulu.Str.RemoveElem(workspacePaths, path)
|
||||
|
||||
if err = util.WriteWorkspacePaths(workspacePaths); nil != err {
|
||||
if err = util.WriteWorkspacePaths(workspacePaths); err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -174,7 +174,7 @@ func removeWorkspaceDirPhysically(c *gin.Context) {
|
|||
path := arg["path"].(string)
|
||||
if gulu.File.IsDir(path) {
|
||||
err := os.RemoveAll(path)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -202,7 +202,7 @@ func getMobileWorkspaces(c *gin.Context) {
|
|||
|
||||
root := filepath.Dir(util.WorkspaceDir)
|
||||
dirs, err := os.ReadDir(root)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read dir [%s] failed: %s", root, err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
|
|
@ -229,7 +229,7 @@ func getWorkspaces(c *gin.Context) {
|
|||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
workspacePaths, err := util.ReadWorkspacePaths()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -299,7 +299,7 @@ func setWorkspaceDir(c *gin.Context) {
|
|||
}
|
||||
|
||||
workspacePaths, err := util.ReadWorkspacePaths()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -310,7 +310,7 @@ func setWorkspaceDir(c *gin.Context) {
|
|||
workspacePaths = gulu.Str.RemoveElem(workspacePaths, path)
|
||||
workspacePaths = append(workspacePaths, path) // 切换的工作空间固定放在最后一个
|
||||
|
||||
if err = util.WriteWorkspacePaths(workspacePaths); nil != err {
|
||||
if err = util.WriteWorkspacePaths(workspacePaths); err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue