mirror of https://github.com/Xhofe/alist
🔥 replace encoding/json with jsoniter
parent
7cf30836bf
commit
beb06f2f7f
|
@ -1,7 +1,6 @@
|
||||||
package bootstrap
|
package bootstrap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -28,7 +27,7 @@ func InitConf() {
|
||||||
log.Fatalf("reading config file error:%s", err.Error())
|
log.Fatalf("reading config file error:%s", err.Error())
|
||||||
}
|
}
|
||||||
conf.Conf = new(conf.Config)
|
conf.Conf = new(conf.Config)
|
||||||
err = json.Unmarshal(config, conf.Conf)
|
err = utils.Json.Unmarshal(config, conf.Conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("load config error: %s", err.Error())
|
log.Fatalf("load config error: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
6
build.sh
6
build.sh
|
@ -26,7 +26,7 @@ if [ "$1" == "docker" ]; then
|
||||||
-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
|
-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
|
||||||
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
|
-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
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -68,9 +68,9 @@ ldflags="\
|
||||||
"
|
"
|
||||||
|
|
||||||
if [ "$1" == "release" ]; then
|
if [ "$1" == "release" ]; then
|
||||||
xgo -out alist -ldflags="$ldflags" .
|
xgo -out alist -ldflags="$ldflags" -tags=jsoniter .
|
||||||
else
|
else
|
||||||
xgo -targets=linux/amd64,windows/amd64 -out alist -ldflags="$ldflags" .
|
xgo -targets=linux/amd64,windows/amd64 -out alist -ldflags="$ldflags" -tags=jsoniter .
|
||||||
fi
|
fi
|
||||||
mkdir "build"
|
mkdir "build"
|
||||||
mv alist-* build
|
mv alist-* build
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -158,7 +157,7 @@ func (driver Cloud189) Login(account *model.Account) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(res.Body(), &loginResp)
|
err = utils.Json.Unmarshal(res.Body(), &loginResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dstDirFile, err := driver.File(dstDir, account)
|
dstDirFile, err := driver.File(dstDir, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -249,7 +247,7 @@ func (driver Cloud189) Move(src string, dst string, account *model.Account) erro
|
||||||
"isFolder": isFolder,
|
"isFolder": isFolder,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
taskInfosBytes, err := json.Marshal(taskInfos)
|
taskInfosBytes, err := utils.Json.Marshal(taskInfos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -305,7 +303,7 @@ func (driver Cloud189) Copy(src string, dst string, account *model.Account) erro
|
||||||
"isFolder": isFolder,
|
"isFolder": isFolder,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
taskInfosBytes, err := json.Marshal(taskInfos)
|
taskInfosBytes, err := utils.Json.Marshal(taskInfos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -335,7 +333,7 @@ func (driver Cloud189) Delete(path string, account *model.Account) error {
|
||||||
"isFolder": isFolder,
|
"isFolder": isFolder,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
taskInfosBytes, err := json.Marshal(taskInfos)
|
taskInfosBytes, err := utils.Json.Marshal(taskInfos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -424,9 +422,6 @@ func (driver Cloud189) Upload(file *model.FileStream, account *model.Account) er
|
||||||
"sliceMd5": utils.GetMD5Encode(strings.Join(md5s, "\n")),
|
"sliceMd5": utils.GetMD5Encode(strings.Join(md5s, "\n")),
|
||||||
"lazyCheck": "1",
|
"lazyCheck": "1",
|
||||||
}, account)
|
}, account)
|
||||||
if err == nil {
|
|
||||||
_ = base.DeleteCache(file.ParentPath, account)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,11 @@ func (driver Shandian) Upload(file *model.FileStream, account *model.Account) er
|
||||||
"id": parentId,
|
"id": parentId,
|
||||||
"name": file.GetFileName(),
|
"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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import jsoniter "github.com/json-iterator/go"
|
||||||
|
|
||||||
|
var Json = jsoniter.ConfigCompatibleWithStandardLibrary
|
Loading…
Reference in New Issue