Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f57edd277 | |||
| cf0ee224f7 |
@@ -118,12 +118,12 @@ func PKCS7UnPadding(origData []byte, blocksize int) []byte {
|
||||
if blocksize <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// 检查原始数据是否为空
|
||||
if origData == nil || len(origData) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// 检查数据长度是否为块大小的整数倍
|
||||
if len(origData)%blocksize != 0 {
|
||||
return nil
|
||||
@@ -137,7 +137,7 @@ func PKCS7UnPadding(origData []byte, blocksize int) []byte {
|
||||
if length-unpadding <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// 返回去除填充后的数据
|
||||
return origData[:(length - unpadding)]
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ var (
|
||||
// MigrateTables holds the tables that need to be auto-migrated on database initialization
|
||||
MigrateTables []any
|
||||
// Init is an optional initialization function that can be executed after database connection is established
|
||||
Init *func() = nil
|
||||
InitFunc *func() error = nil
|
||||
)
|
||||
|
||||
// NewDatabase creates a new database connection based on the provided driver type
|
||||
@@ -36,11 +36,6 @@ func NewDatabase(driver string, dsn []string, options *types.SqlOptions) (db *go
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Execute the Init function if it's not nil
|
||||
if Init != nil {
|
||||
(*Init)()
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
||||
|
||||
@@ -73,7 +68,7 @@ func NewMysql(dsn []string, options *types.SqlOptions) (gormDb *gorm.DB, err err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
// SetMaxIdleConns 用于设置连接池中空闲连接的最大数量。
|
||||
sqlDB.SetMaxIdleConns(options.MaxIdleConns)
|
||||
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
||||
@@ -118,7 +113,7 @@ func NewPostgres(dsn []string, options *types.SqlOptions) (gormDb *gorm.DB, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
// SetMaxIdleConns 用于设置连接池中空闲连接的最大数量。
|
||||
sqlDB.SetMaxIdleConns(options.MaxIdleConns)
|
||||
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
||||
@@ -134,4 +129,4 @@ func NewPostgres(dsn []string, options *types.SqlOptions) (gormDb *gorm.DB, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
18
with/init.go
Normal file
18
with/init.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package with
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/print"
|
||||
)
|
||||
|
||||
func InitData() {
|
||||
// Execute the Init function if it's not nil
|
||||
if database.InitFunc != nil {
|
||||
err := (*database.InitFunc)()
|
||||
if err != nil {
|
||||
print.Error(errcode.ErrEtcd.Error())
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user