🔥 replace encoding/json with jsoniter

This commit is contained in:
微凉
2022-01-03 20:25:22 +08:00
parent 7cf30836bf
commit beb06f2f7f
6 changed files with 18 additions and 16 deletions

View File

@ -1,7 +1,6 @@
package bootstrap
import (
"encoding/json"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/utils"
log "github.com/sirupsen/logrus"
@ -28,7 +27,7 @@ func InitConf() {
log.Fatalf("reading config file error:%s", err.Error())
}
conf.Conf = new(conf.Config)
err = json.Unmarshal(config, conf.Conf)
err = utils.Json.Unmarshal(config, conf.Conf)
if err != nil {
log.Fatalf("load config error: %s", err.Error())
}

View File

@ -26,7 +26,7 @@ if [ "$1" == "docker" ]; then
-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
"
go build -o ./bin/alist -ldflags="$ldflags" alist.go
go build -o ./bin/alist -ldflags="$ldflags" -tags=jsoniter alist.go
exit 0
fi
@ -68,9 +68,9 @@ ldflags="\
"
if [ "$1" == "release" ]; then
xgo -out alist -ldflags="$ldflags" .
xgo -out alist -ldflags="$ldflags" -tags=jsoniter .
else
xgo -targets=linux/amd64,windows/amd64 -out alist -ldflags="$ldflags" .
xgo -targets=linux/amd64,windows/amd64 -out alist -ldflags="$ldflags" -tags=jsoniter .
fi
mkdir "build"
mv alist-* build

View File

@ -10,7 +10,6 @@ import (
"crypto/x509"
"encoding/base64"
"encoding/hex"
"encoding/json"
"encoding/pem"
"errors"
"fmt"
@ -158,7 +157,7 @@ func (driver Cloud189) Login(account *model.Account) error {
if err != nil {
return err
}
err = json.Unmarshal(res.Body(), &loginResp)
err = utils.Json.Unmarshal(res.Body(), &loginResp)
if err != nil {
log.Error(err.Error())
return err

View File

@ -5,7 +5,6 @@ import (
"crypto/md5"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
@ -233,7 +232,6 @@ func (driver Cloud189) Move(src string, dst string, account *model.Account) erro
if err != nil {
return err
}
dstDirFile, err := driver.File(dstDir, account)
if err != nil {
return err
@ -249,7 +247,7 @@ func (driver Cloud189) Move(src string, dst string, account *model.Account) erro
"isFolder": isFolder,
},
}
taskInfosBytes, err := json.Marshal(taskInfos)
taskInfosBytes, err := utils.Json.Marshal(taskInfos)
if err != nil {
return err
}
@ -305,7 +303,7 @@ func (driver Cloud189) Copy(src string, dst string, account *model.Account) erro
"isFolder": isFolder,
},
}
taskInfosBytes, err := json.Marshal(taskInfos)
taskInfosBytes, err := utils.Json.Marshal(taskInfos)
if err != nil {
return err
}
@ -335,7 +333,7 @@ func (driver Cloud189) Delete(path string, account *model.Account) error {
"isFolder": isFolder,
},
}
taskInfosBytes, err := json.Marshal(taskInfos)
taskInfosBytes, err := utils.Json.Marshal(taskInfos)
if err != nil {
return err
}
@ -424,9 +422,6 @@ func (driver Cloud189) Upload(file *model.FileStream, account *model.Account) er
"sliceMd5": utils.GetMD5Encode(strings.Join(md5s, "\n")),
"lazyCheck": "1",
}, account)
if err == nil {
_ = base.DeleteCache(file.ParentPath, account)
}
return err
}

View File

@ -235,7 +235,11 @@ func (driver Shandian) Upload(file *model.FileStream, account *model.Account) er
"id": parentId,
"name": file.GetFileName(),
}
_, err = driver.Post("https://shandianpan.com/api/pan/upload", data, &resp, account)
res, err := driver.Post("https://shandianpan.com/api/pan/upload", data, nil, account)
if err != nil {
return err
}
err = utils.Json.Unmarshal(res, &resp)
if err != nil {
return err
}

5
utils/json.go Normal file
View File

@ -0,0 +1,5 @@
package utils
import jsoniter "github.com/json-iterator/go"
var Json = jsoniter.ConfigCompatibleWithStandardLibrary