mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +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
|
|
@ -79,15 +79,15 @@ func LoadAssetsTexts() {
|
|||
|
||||
start := time.Now()
|
||||
data, err := filelock.ReadFile(assetsTextsPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read assets texts failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
assetsTextsLock.Lock()
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &assetsTexts); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &assetsTexts); err != nil {
|
||||
logging.LogErrorf("unmarshal assets texts failed: %s", err)
|
||||
if err = filelock.Remove(assetsTextsPath); nil != err {
|
||||
if err = filelock.Remove(assetsTextsPath); err != nil {
|
||||
logging.LogErrorf("removed corrupted assets texts failed: %s", err)
|
||||
}
|
||||
return
|
||||
|
|
@ -110,7 +110,7 @@ func SaveAssetsTexts() {
|
|||
|
||||
assetsTextsLock.Lock()
|
||||
data, err := gulu.JSON.MarshalIndentJSON(assetsTexts, "", " ")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal assets texts failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ func SaveAssetsTexts() {
|
|||
|
||||
assetsPath := GetDataAssetsAbsPath()
|
||||
assetsTextsPath := filepath.Join(assetsPath, "ocr-texts.json")
|
||||
if err = filelock.WriteFile(assetsTextsPath, data); nil != err {
|
||||
if err = filelock.WriteFile(assetsTextsPath, data); err != nil {
|
||||
logging.LogErrorf("write assets texts failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ func Tesseract(imgAbsPath string) (ret []map[string]interface{}) {
|
|||
}
|
||||
|
||||
info, err := os.Stat(imgAbsPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -213,7 +213,7 @@ func Tesseract(imgAbsPath string) (ret []map[string]interface{}) {
|
|||
return
|
||||
}
|
||||
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("tesseract [path=%s, size=%d] failed: %s", imgAbsPath, info.Size(), err)
|
||||
return
|
||||
}
|
||||
|
|
@ -341,14 +341,14 @@ func getTesseractVer() (ret string) {
|
|||
cmd := exec.Command(TesseractBin, "--version")
|
||||
gulu.CmdAttr(cmd)
|
||||
data, err := cmd.CombinedOutput()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "executable file not found") {
|
||||
// macOS 端 Tesseract OCR 安装后不识别 https://github.com/siyuan-note/siyuan/issues/7107
|
||||
TesseractBin = "/usr/local/bin/tesseract"
|
||||
cmd = exec.Command(TesseractBin, "--version")
|
||||
gulu.CmdAttr(cmd)
|
||||
data, err = cmd.CombinedOutput()
|
||||
if nil != err && strings.Contains(err.Error(), "executable file not found") {
|
||||
if err != nil && strings.Contains(err.Error(), "executable file not found") {
|
||||
TesseractBin = "/opt/homebrew/bin/tesseract"
|
||||
cmd = exec.Command(TesseractBin, "--version")
|
||||
gulu.CmdAttr(cmd)
|
||||
|
|
@ -356,7 +356,7 @@ func getTesseractVer() (ret string) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -380,7 +380,7 @@ func getTesseractLangs() (ret []string) {
|
|||
cmd := exec.Command(TesseractBin, "--list-langs")
|
||||
gulu.CmdAttr(cmd)
|
||||
data, err := cmd.CombinedOutput()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue