refactor: optimize driver initialization need to manually deserialize and assign values, and remove redundant driver registration parameters (#2691)
* refactor: optimize driver initialization need to manually deserialize and assign values, and remove redundant driver registration parameters * fix typo Co-authored-by: Noah Hsu <i@nn.ci>
This commit is contained in:
@ -32,15 +32,10 @@ func (x *Thunder) Config() driver.Config {
|
||||
}
|
||||
|
||||
func (x *Thunder) GetAddition() driver.Additional {
|
||||
return x.Addition
|
||||
return &x.Addition
|
||||
}
|
||||
|
||||
func (x *Thunder) Init(ctx context.Context, storage model.Storage) (err error) {
|
||||
x.Storage = storage
|
||||
if err = utils.Json.UnmarshalFromString(x.Storage.Addition, &x.Addition); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (x *Thunder) Init(ctx context.Context) (err error) {
|
||||
// 初始化所需参数
|
||||
if x.XunLeiCommon == nil {
|
||||
x.XunLeiCommon = &XunLeiCommon{
|
||||
@ -126,15 +121,10 @@ func (x *ThunderExpert) Config() driver.Config {
|
||||
}
|
||||
|
||||
func (x *ThunderExpert) GetAddition() driver.Additional {
|
||||
return x.ExpertAddition
|
||||
return &x.ExpertAddition
|
||||
}
|
||||
|
||||
func (x *ThunderExpert) Init(ctx context.Context, storage model.Storage) (err error) {
|
||||
x.Storage = storage
|
||||
if err = utils.Json.UnmarshalFromString(x.Storage.Addition, &x.ExpertAddition); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (x *ThunderExpert) Init(ctx context.Context) (err error) {
|
||||
// 防止重复登录
|
||||
identity := x.GetIdentity()
|
||||
if identity != x.identity || !x.IsLogin() {
|
||||
|
@ -93,10 +93,10 @@ var configExpert = driver.Config{
|
||||
}
|
||||
|
||||
func init() {
|
||||
op.RegisterDriver(config, func() driver.Driver {
|
||||
op.RegisterDriver(func() driver.Driver {
|
||||
return &Thunder{}
|
||||
})
|
||||
op.RegisterDriver(configExpert, func() driver.Driver {
|
||||
op.RegisterDriver(func() driver.Driver {
|
||||
return &ThunderExpert{}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user