mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-17 20:48:06 +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
|
|
@ -264,7 +264,7 @@ func GetAttributeViewName(avID string) (ret string, err error) {
|
|||
|
||||
func GetAttributeViewNameByPath(avJSONPath string) (ret string, err error) {
|
||||
data, err := filelock.ReadFile(avJSONPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read attribute view [%s] failed: %s", avJSONPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -296,10 +296,10 @@ func ParseAttributeView(avID string) (ret *AttributeView, err error) {
|
|||
}
|
||||
|
||||
ret = &AttributeView{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {
|
||||
if strings.Contains(err.Error(), ".relation.contents of type av.Value") {
|
||||
mapAv := map[string]interface{}{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &mapAv); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &mapAv); err != nil {
|
||||
logging.LogErrorf("unmarshal attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -338,12 +338,12 @@ func ParseAttributeView(avID string) (ret *AttributeView, err error) {
|
|||
}
|
||||
|
||||
data, err = gulu.JSON.MarshalJSON(mapAv)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {
|
||||
logging.LogErrorf("unmarshal attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -524,13 +524,13 @@ func SaveAttributeView(av *AttributeView) (err error) {
|
|||
} else {
|
||||
data, err = gulu.JSON.MarshalIndentJSON(av, "", "\t")
|
||||
}
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal attribute view [%s] failed: %s", av.ID, err)
|
||||
return
|
||||
}
|
||||
|
||||
avJSONPath := GetAttributeViewDataPath(av.ID)
|
||||
if err = filelock.WriteFile(avJSONPath, data); nil != err {
|
||||
if err = filelock.WriteFile(avJSONPath, data); err != nil {
|
||||
logging.LogErrorf("save attribute view [%s] failed: %s", av.ID, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -645,11 +645,11 @@ func (av *AttributeView) GetBlockKey() (ret *Key) {
|
|||
func (av *AttributeView) ShallowClone() (ret *AttributeView) {
|
||||
ret = &AttributeView{}
|
||||
data, err := gulu.JSON.MarshalJSON(av)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal attribute view [%s] failed: %s", av.ID, err)
|
||||
return nil
|
||||
}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {
|
||||
logging.LogErrorf("unmarshal attribute view [%s] failed: %s", av.ID, err)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -708,7 +708,7 @@ func GetAttributeViewDataPath(avID string) (ret string) {
|
|||
av := filepath.Join(util.DataDir, "storage", "av")
|
||||
ret = filepath.Join(av, avID+".json")
|
||||
if !gulu.File.IsDir(av) {
|
||||
if err := os.MkdirAll(av, 0755); nil != err {
|
||||
if err := os.MkdirAll(av, 0755); err != nil {
|
||||
logging.LogErrorf("create attribute view dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue