chore: go fmt

pull/1604/head
Noah Hsu 2022-08-03 14:26:59 +08:00
parent 721f18a7f4
commit b51e664543
41 changed files with 100 additions and 74 deletions

View File

@ -7,9 +7,8 @@ import (
"path/filepath"
"strings"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/alist-org/alist/v3/pkg/utils"

2
go.mod
View File

@ -14,6 +14,7 @@ require (
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/winfsp/cgofuse v1.5.0
gorm.io/driver/mysql v1.3.4
gorm.io/driver/postgres v1.3.7
gorm.io/driver/sqlite v1.3.4
@ -46,7 +47,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/winfsp/cgofuse v1.5.0 // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/net v0.0.0-20220531201128-c960675eff93 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect

2
go.sum
View File

@ -1,8 +1,6 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/Xhofe/go-cache v0.0.0-20220613125742-9554c28ee448 h1:0TL8OCXaQD1YhG0D3YAfDcm/n4QRo4rCGiU0Pa5nQC4=
github.com/Xhofe/go-cache v0.0.0-20220613125742-9554c28ee448/go.mod h1:sSBbaOg90XwWKtpT56kVujF0bIeVITnPlssLclogS04=
github.com/Xhofe/go-cache v0.0.0-20220723083548-714439c8af9a h1:RenIAa2q4H8UcS/cqmwdT1WCWIAH5aumP8m8RpbqVsE=
github.com/Xhofe/go-cache v0.0.0-20220723083548-714439c8af9a/go.mod h1:sSBbaOg90XwWKtpT56kVujF0bIeVITnPlssLclogS04=
github.com/caarlos0/env/v6 v6.9.3 h1:Tyg69hoVXDnpO5Qvpsu8EoquarbPyQb+YwExWHP8wWU=

View File

@ -3,13 +3,14 @@ package aria2
import (
"context"
"fmt"
"path/filepath"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/alist-org/alist/v3/pkg/task"
"github.com/google/uuid"
"github.com/pkg/errors"
"path/filepath"
)
func AddURI(ctx context.Context, uri string, dstDirPath string) error {

View File

@ -2,13 +2,14 @@ package aria2
import (
"context"
"time"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/setting"
"github.com/alist-org/alist/v3/pkg/aria2/rpc"
"github.com/alist-org/alist/v3/pkg/task"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"time"
)
var DownTaskManager = task.NewTaskManager[string](3)

View File

@ -1,12 +1,12 @@
package bootstrap
import (
conf2 "github.com/alist-org/alist/v3/internal/conf"
"io/ioutil"
"os"
"path/filepath"
"github.com/alist-org/alist/v3/cmd/args"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/caarlos0/env/v6"
log "github.com/sirupsen/logrus"
@ -20,8 +20,8 @@ func InitConfig() {
if err != nil {
log.Fatalf("failed to create config file: %+v", err)
}
conf2.Conf = conf2.DefaultConfig()
if !utils.WriteToJson(args.Config, conf2.Conf) {
conf.Conf = conf.DefaultConfig()
if !utils.WriteToJson(args.Config, conf.Conf) {
log.Fatalf("failed to create default config file")
}
} else {
@ -29,14 +29,14 @@ func InitConfig() {
if err != nil {
log.Fatalf("reading config file error:%s", err.Error())
}
conf2.Conf = conf2.DefaultConfig()
err = utils.Json.Unmarshal(configBytes, conf2.Conf)
conf.Conf = conf.DefaultConfig()
err = utils.Json.Unmarshal(configBytes, conf.Conf)
if err != nil {
log.Fatalf("load config error: %s", err.Error())
}
log.Debugf("config:%+v", conf2.Conf)
log.Debugf("config:%+v", conf.Conf)
// update config.json struct
confBody, err := utils.Json.MarshalIndent(conf2.Conf, "", " ")
confBody, err := utils.Json.MarshalIndent(conf.Conf, "", " ")
if err != nil {
log.Fatalf("marshal config error:%s", err.Error())
}
@ -45,28 +45,28 @@ func InitConfig() {
log.Fatalf("update config struct error: %s", err.Error())
}
}
if !conf2.Conf.Force {
if !conf.Conf.Force {
confFromEnv()
}
// convert abs path
var absPath string
var err error
if !filepath.IsAbs(conf2.Conf.TempDir) {
absPath, err = filepath.Abs(conf2.Conf.TempDir)
if !filepath.IsAbs(conf.Conf.TempDir) {
absPath, err = filepath.Abs(conf.Conf.TempDir)
if err != nil {
log.Fatalf("get abs path error: %s", err.Error())
}
}
conf2.Conf.TempDir = absPath
err = os.RemoveAll(filepath.Join(conf2.Conf.TempDir))
conf.Conf.TempDir = absPath
err = os.RemoveAll(filepath.Join(conf.Conf.TempDir))
if err != nil {
log.Errorln("failed delete temp file:", err)
}
err = os.MkdirAll(conf2.Conf.TempDir, 0700)
err = os.MkdirAll(conf.Conf.TempDir, 0700)
if err != nil {
log.Fatalf("create temp dir error: %s", err.Error())
}
log.Debugf("config: %+v", conf2.Conf)
log.Debugf("config: %+v", conf.Conf)
}
func confFromEnv() {
@ -75,7 +75,7 @@ func confFromEnv() {
prefix = ""
}
log.Infof("load config from env with prefix: %s", prefix)
if err := env.Parse(conf2.Conf, env.Options{
if err := env.Parse(conf.Conf, env.Options{
Prefix: prefix,
}); err != nil {
log.Fatalf("load config from env error: %s", err.Error())

View File

@ -2,6 +2,7 @@ package data
import (
"context"
"github.com/alist-org/alist/v3/cmd/args"
"github.com/alist-org/alist/v3/internal/db"
"github.com/alist-org/alist/v3/internal/message"

View File

@ -2,6 +2,10 @@ package bootstrap
import (
"fmt"
stdlog "log"
"strings"
"time"
"github.com/alist-org/alist/v3/cmd/args"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/db"
@ -12,9 +16,6 @@ import (
"gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema"
stdlog "log"
"strings"
"time"
)
func InitDB() {

View File

@ -1,11 +1,11 @@
package bootstrap
import (
"github.com/alist-org/alist/v3/internal/conf"
"log"
"time"
"github.com/alist-org/alist/v3/cmd/args"
"github.com/alist-org/alist/v3/internal/conf"
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
"github.com/sirupsen/logrus"
)

View File

@ -1,9 +1,10 @@
package db
import (
"log"
"github.com/alist-org/alist/v3/internal/model"
"gorm.io/gorm"
"log"
)
var db gorm.DB

View File

@ -1,6 +1,9 @@
package db
import (
stdpath "path"
"time"
"github.com/Xhofe/go-cache"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
@ -8,8 +11,6 @@ import (
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/pkg/errors"
"gorm.io/gorm"
stdpath "path"
"time"
)
var metaCache = cache.NewMemCache(cache.WithShards[*model.Meta](2))

View File

@ -1,12 +1,13 @@
package db
import (
"testing"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/pkg/errors"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"testing"
)
func init() {

View File

@ -2,6 +2,7 @@ package db
import (
"fmt"
"github.com/alist-org/alist/v3/internal/model"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

View File

@ -1,12 +1,13 @@
package db
import (
"time"
"github.com/Xhofe/go-cache"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/singleflight"
"github.com/pkg/errors"
"time"
)
var userCache = cache.NewMemCache(cache.WithShards[*model.User](2))

View File

@ -2,6 +2,7 @@ package db
import (
"fmt"
"github.com/alist-org/alist/v3/internal/conf"
)

View File

@ -2,6 +2,7 @@ package errs
import (
"errors"
pkgerr "github.com/pkg/errors"
)

View File

@ -6,12 +6,11 @@ import (
stdpath "path"
"sync/atomic"
"github.com/alist-org/alist/v3/pkg/task"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/alist-org/alist/v3/pkg/task"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/pkg/errors"
)

View File

@ -2,12 +2,13 @@ package fs
import (
"context"
stdpath "path"
"time"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/pkg/errors"
stdpath "path"
"time"
)
func get(ctx context.Context, path string) (model.Obj, error) {

View File

@ -2,6 +2,7 @@ package fs
import (
"context"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/pkg/errors"

View File

@ -2,13 +2,14 @@ package fs
import (
"context"
"regexp"
"strings"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"regexp"
"strings"
)
// List files

View File

@ -3,16 +3,17 @@ package fs
import (
"context"
"fmt"
"sync/atomic"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/alist-org/alist/v3/pkg/task"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/pkg/errors"
"sync/atomic"
)
var UploadTaskManager = task.NewTaskManager[uint64](3, func(tid *uint64) {
var UploadTaskManager = task.NewTaskManager(3, func(tid *uint64) {
atomic.AddUint64(tid, 1)
})

View File

@ -1,7 +1,6 @@
package fs
import (
"github.com/alist-org/alist/v3/internal/operations"
"io"
"mime"
"net/http"
@ -10,6 +9,7 @@ import (
"strings"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/pkg/errors"
)

View File

@ -1,10 +1,11 @@
package message
import (
"time"
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"time"
)
type Post struct {

View File

@ -1,11 +1,11 @@
package operations
import (
"github.com/alist-org/alist/v3/internal/errs"
stdpath "path"
"strings"
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

View File

@ -2,7 +2,6 @@ package operations
import (
"context"
log "github.com/sirupsen/logrus"
"sort"
"strings"
"time"
@ -13,6 +12,7 @@ import (
"github.com/alist-org/alist/v3/pkg/generic_sync"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
// Although the driver type is stored,

View File

@ -2,9 +2,9 @@ package operations_test
import (
"context"
"github.com/alist-org/alist/v3/internal/db"
"testing"
"github.com/alist-org/alist/v3/internal/db"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/alist-org/alist/v3/pkg/utils"

View File

@ -1,8 +1,9 @@
package setting
import (
"github.com/alist-org/alist/v3/internal/db"
"strconv"
"github.com/alist-org/alist/v3/internal/db"
)
func GetByKey(key string, defaultValue ...string) string {

View File

@ -1,11 +1,12 @@
package sign
import (
"sync"
"time"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/setting"
"github.com/alist-org/alist/v3/pkg/sign"
"sync"
"time"
)
var once sync.Once

View File

@ -1,9 +1,10 @@
package common
import (
"time"
"github.com/golang-jwt/jwt/v4"
"github.com/pkg/errors"
"time"
)
var SecretKey []byte

View File

@ -2,10 +2,11 @@ package common
import (
"fmt"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/setting"
"net/http"
"strings"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/setting"
)
func GetBaseUrl(r *http.Request) string {

View File

@ -2,9 +2,6 @@ package common
import (
"fmt"
"github.com/alist-org/alist/v3/internal/model"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"io"
"io/ioutil"
"net/http"
@ -12,6 +9,10 @@ import (
"os"
"strconv"
"strings"
"github.com/alist-org/alist/v3/internal/model"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
var HttpClient = &http.Client{}

View File

@ -1,13 +1,14 @@
package handles
import (
stdpath "path"
"github.com/alist-org/alist/v3/internal/aria2"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/db"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"
stdpath "path"
)
type SetAria2Req struct {

View File

@ -2,15 +2,15 @@ package handles
import (
"fmt"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/sign"
stdpath "path"
"strings"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/setting"
"github.com/alist-org/alist/v3/internal/sign"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"

View File

@ -2,6 +2,7 @@ package handles
import (
"fmt"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"

View File

@ -2,6 +2,10 @@ package handles
import (
"fmt"
stdpath "path"
"strconv"
"time"
"github.com/alist-org/alist/v3/internal/db"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/fs"
@ -9,9 +13,6 @@ import (
"github.com/alist-org/alist/v3/internal/sign"
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"
stdpath "path"
"strconv"
"time"
)
type MkdirOrLinkReq struct {

View File

@ -1,6 +1,9 @@
package handles
import (
"strconv"
"strings"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/db"
"github.com/alist-org/alist/v3/internal/model"
@ -8,8 +11,6 @@ import (
"github.com/alist-org/alist/v3/pkg/utils/random"
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"
"strconv"
"strings"
)
func ResetToken(c *gin.Context) {

View File

@ -1,6 +1,8 @@
package middlewares
import (
stdpath "path"
"github.com/alist-org/alist/v3/internal/db"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
@ -9,7 +11,6 @@ import (
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
stdpath "path"
)
func Down(c *gin.Context) {

View File

@ -2,13 +2,14 @@ package server
import (
"context"
"net/http"
"github.com/alist-org/alist/v3/internal/db"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/server/webdav"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"net/http"
)
var handler *webdav.Handler

View File

@ -6,12 +6,13 @@ package webdav
import (
"context"
"github.com/alist-org/alist/v3/internal/db"
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
"net/http"
"path"
"path/filepath"
"github.com/alist-org/alist/v3/internal/db"
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
)
// slashClean is equivalent to but slightly more efficient than

View File

@ -10,11 +10,12 @@ import (
"encoding/xml"
"errors"
"fmt"
"github.com/alist-org/alist/v3/internal/model"
"mime"
"net/http"
"path"
"strconv"
"github.com/alist-org/alist/v3/internal/model"
)
// Proppatch describes a property update instruction as defined in RFC 4918.

View File

@ -8,18 +8,19 @@ package webdav // import "golang.org/x/net/webdav"
import (
"errors"
"fmt"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/sign"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/server/common"
"net/http"
"net/url"
"os"
"path"
"strings"
"time"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/sign"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/server/common"
)
type Handler struct {