From b474eefd87676ee5db011a961fb6b78f942dd3dd Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Sat, 25 Jun 2022 21:36:35 +0800 Subject: [PATCH] chore: rename store to db --- bootstrap/db.go | 6 +++--- internal/aria2/aria2_test.go | 3 +-- internal/{store => db}/account.go | 2 +- internal/{store => db}/meta.go | 2 +- internal/{store => db}/meta_test.go | 2 +- internal/{store => db}/store.go | 2 +- internal/{store => db}/user.go | 2 +- internal/{store => db}/util.go | 2 +- internal/operations/account.go | 10 +++++----- internal/operations/account_test.go | 6 +++--- internal/server/controllers/login.go | 4 ++-- internal/server/middlewares/auth.go | 4 ++-- 12 files changed, 22 insertions(+), 23 deletions(-) rename internal/{store => db}/account.go (99%) rename internal/{store => db}/meta.go (99%) rename internal/{store => db}/meta_test.go (98%) rename internal/{store => db}/store.go (95%) rename internal/{store => db}/user.go (99%) rename internal/{store => db}/util.go (94%) diff --git a/bootstrap/db.go b/bootstrap/db.go index ed82ef1d..e1526c11 100644 --- a/bootstrap/db.go +++ b/bootstrap/db.go @@ -3,7 +3,7 @@ package bootstrap import ( "github.com/alist-org/alist/v3/cmd/args" "github.com/alist-org/alist/v3/internal/conf" - "github.com/alist-org/alist/v3/internal/store" + "github.com/alist-org/alist/v3/internal/db" log "github.com/sirupsen/logrus" "gorm.io/driver/sqlite" "gorm.io/gorm" @@ -30,10 +30,10 @@ func InitDB() { Logger: newLogger, } if args.Dev { - db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), gormConfig) + dB, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), gormConfig) if err != nil { panic("failed to connect database") } - store.Init(db) + db.Init(dB) } } diff --git a/internal/aria2/aria2_test.go b/internal/aria2/aria2_test.go index 6ef04cea..1ab416a1 100644 --- a/internal/aria2/aria2_test.go +++ b/internal/aria2/aria2_test.go @@ -6,7 +6,6 @@ import ( conf2 "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/operations" - "github.com/alist-org/alist/v3/internal/store" "github.com/alist-org/alist/v3/pkg/task" "gorm.io/driver/sqlite" "gorm.io/gorm" @@ -26,7 +25,7 @@ func init() { if err != nil { panic("failed to connect database") } - store.Init(db) + db.Init(db) } func TestConnect(t *testing.T) { diff --git a/internal/store/account.go b/internal/db/account.go similarity index 99% rename from internal/store/account.go rename to internal/db/account.go index 949df39f..3a0c2437 100644 --- a/internal/store/account.go +++ b/internal/db/account.go @@ -1,4 +1,4 @@ -package store +package db import ( "github.com/alist-org/alist/v3/internal/model" diff --git a/internal/store/meta.go b/internal/db/meta.go similarity index 99% rename from internal/store/meta.go rename to internal/db/meta.go index 60bda4c0..10604363 100644 --- a/internal/store/meta.go +++ b/internal/db/meta.go @@ -1,4 +1,4 @@ -package store +package db import ( "github.com/Xhofe/go-cache" diff --git a/internal/store/meta_test.go b/internal/db/meta_test.go similarity index 98% rename from internal/store/meta_test.go rename to internal/db/meta_test.go index af7feb16..22024146 100644 --- a/internal/store/meta_test.go +++ b/internal/db/meta_test.go @@ -1,4 +1,4 @@ -package store +package db import ( "github.com/alist-org/alist/v3/internal/model" diff --git a/internal/store/store.go b/internal/db/store.go similarity index 95% rename from internal/store/store.go rename to internal/db/store.go index 3f92042e..6ea5645f 100644 --- a/internal/store/store.go +++ b/internal/db/store.go @@ -1,4 +1,4 @@ -package store +package db import ( "github.com/alist-org/alist/v3/internal/model" diff --git a/internal/store/user.go b/internal/db/user.go similarity index 99% rename from internal/store/user.go rename to internal/db/user.go index 1219de8c..b41d199d 100644 --- a/internal/store/user.go +++ b/internal/db/user.go @@ -1,4 +1,4 @@ -package store +package db import ( "github.com/Xhofe/go-cache" diff --git a/internal/store/util.go b/internal/db/util.go similarity index 94% rename from internal/store/util.go rename to internal/db/util.go index 1a2f32ef..50582aa4 100644 --- a/internal/store/util.go +++ b/internal/db/util.go @@ -1,4 +1,4 @@ -package store +package db import ( "fmt" diff --git a/internal/operations/account.go b/internal/operations/account.go index 494c094f..17c28f8b 100644 --- a/internal/operations/account.go +++ b/internal/operations/account.go @@ -7,9 +7,9 @@ import ( "strings" "time" + "github.com/alist-org/alist/v3/internal/db" "github.com/alist-org/alist/v3/internal/driver" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/store" "github.com/alist-org/alist/v3/pkg/generic_sync" "github.com/alist-org/alist/v3/pkg/utils" "github.com/pkg/errors" @@ -33,7 +33,7 @@ func GetAccountByVirtualPath(virtualPath string) (driver.Driver, error) { func CreateAccount(ctx context.Context, account model.Account) error { account.Modified = time.Now() account.VirtualPath = utils.StandardizePath(account.VirtualPath) - err := store.CreateAccount(&account) + err := db.CreateAccount(&account) if err != nil { return errors.WithMessage(err, "failed create account in database") } @@ -56,13 +56,13 @@ func CreateAccount(ctx context.Context, account model.Account) error { // get old account first // drop the account then reinitialize func UpdateAccount(ctx context.Context, account model.Account) error { - oldAccount, err := store.GetAccountById(account.ID) + oldAccount, err := db.GetAccountById(account.ID) if err != nil { return errors.WithMessage(err, "failed get old account") } account.Modified = time.Now() account.VirtualPath = utils.StandardizePath(account.VirtualPath) - err = store.UpdateAccount(&account) + err = db.UpdateAccount(&account) if err != nil { return errors.WithMessage(err, "failed update account in database") } @@ -102,7 +102,7 @@ func saveDriverAccount(driver driver.Driver) error { return errors.Wrap(err, "error while marshal addition") } account.Addition = string(bytes) - err = store.UpdateAccount(&account) + err = db.UpdateAccount(&account) if err != nil { return errors.WithMessage(err, "failed update account in database") } diff --git a/internal/operations/account_test.go b/internal/operations/account_test.go index 4f151ffe..7a0f5589 100644 --- a/internal/operations/account_test.go +++ b/internal/operations/account_test.go @@ -2,22 +2,22 @@ package operations_test import ( "context" + "github.com/alist-org/alist/v3/internal/db" "testing" "github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/operations" - "github.com/alist-org/alist/v3/internal/store" "github.com/alist-org/alist/v3/pkg/utils" "gorm.io/driver/sqlite" "gorm.io/gorm" ) func init() { - db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{}) + dB, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{}) if err != nil { panic("failed to connect database") } - store.Init(db) + db.Init(dB) } func TestCreateAccount(t *testing.T) { diff --git a/internal/server/controllers/login.go b/internal/server/controllers/login.go index fd2187f5..599f8cc0 100644 --- a/internal/server/controllers/login.go +++ b/internal/server/controllers/login.go @@ -2,8 +2,8 @@ package controllers import ( "github.com/Xhofe/go-cache" + "github.com/alist-org/alist/v3/internal/db" "github.com/alist-org/alist/v3/internal/server/common" - "github.com/alist-org/alist/v3/internal/store" "github.com/gin-gonic/gin" "time" ) @@ -34,7 +34,7 @@ func Login(c *gin.Context) { common.ErrorResp(c, err, 400) return } - user, err := store.GetUserByName(req.Username) + user, err := db.GetUserByName(req.Username) if err != nil { common.ErrorResp(c, err, 400) return diff --git a/internal/server/middlewares/auth.go b/internal/server/middlewares/auth.go index 199db64d..3f1aed4c 100644 --- a/internal/server/middlewares/auth.go +++ b/internal/server/middlewares/auth.go @@ -1,8 +1,8 @@ package middlewares import ( + "github.com/alist-org/alist/v3/internal/db" "github.com/alist-org/alist/v3/internal/server/common" - "github.com/alist-org/alist/v3/internal/store" "github.com/gin-gonic/gin" ) @@ -14,7 +14,7 @@ func AuthAdmin(c *gin.Context) { c.Abort() return } - user, err := store.GetUserByName(userClaims.Username) + user, err := db.GetUserByName(userClaims.Username) if err != nil { common.ErrorResp(c, err, 401) c.Abort()