config: another fix for Default funcs #193

Merged
vtolstov merged 1 commits from defaults-fix into v3 2023-03-16 07:14:42 +03:00
Showing only changes of commit 36e492314d - Show all commits

View File

@ -126,10 +126,10 @@ func Validate(ctx context.Context, cfg interface{}) error {
var ( var (
// DefaultBeforeLoad default func that runs before config Load // DefaultBeforeLoad default func that runs before config Load
DefaultBeforeLoad = func(ctx context.Context, c Config) error { DefaultBeforeLoad = func(ctx context.Context, c Config) error {
if c.Options().BeforeLoad == nil { for _, fn := range c.Options().BeforeLoad {
if fn == nil {
return nil return nil
} }
for _, fn := range c.Options().BeforeLoad {
if err := fn(ctx, c); err != nil { if err := fn(ctx, c); err != nil {
c.Options().Logger.Errorf(ctx, "%s BeforeLoad err: %v", c.String(), err) c.Options().Logger.Errorf(ctx, "%s BeforeLoad err: %v", c.String(), err)
if !c.Options().AllowFail { if !c.Options().AllowFail {
@ -141,10 +141,10 @@ var (
} }
// DefaultAfterLoad default func that runs after config Load // DefaultAfterLoad default func that runs after config Load
DefaultAfterLoad = func(ctx context.Context, c Config) error { DefaultAfterLoad = func(ctx context.Context, c Config) error {
if c.Options().AfterLoad == nil { for _, fn := range c.Options().AfterLoad {
if fn == nil {
return nil return nil
} }
for _, fn := range c.Options().AfterLoad {
if err := fn(ctx, c); err != nil { if err := fn(ctx, c); err != nil {
c.Options().Logger.Errorf(ctx, "%s AfterLoad err: %v", c.String(), err) c.Options().Logger.Errorf(ctx, "%s AfterLoad err: %v", c.String(), err)
if !c.Options().AllowFail { if !c.Options().AllowFail {
@ -156,10 +156,10 @@ var (
} }
// DefaultBeforeSave default func that runs befora config Save // DefaultBeforeSave default func that runs befora config Save
DefaultBeforeSave = func(ctx context.Context, c Config) error { DefaultBeforeSave = func(ctx context.Context, c Config) error {
if c.Options().BeforeSave == nil { for _, fn := range c.Options().BeforeSave {
if fn == nil {
return nil return nil
} }
for _, fn := range c.Options().BeforeSave {
if err := fn(ctx, c); err != nil { if err := fn(ctx, c); err != nil {
c.Options().Logger.Errorf(ctx, "%s BeforeSave err: %v", c.String(), err) c.Options().Logger.Errorf(ctx, "%s BeforeSave err: %v", c.String(), err)
if !c.Options().AllowFail { if !c.Options().AllowFail {
@ -171,10 +171,10 @@ var (
} }
// DefaultAfterSave default func that runs after config Save // DefaultAfterSave default func that runs after config Save
DefaultAfterSave = func(ctx context.Context, c Config) error { DefaultAfterSave = func(ctx context.Context, c Config) error {
if c.Options().AfterSave == nil { for _, fn := range c.Options().AfterSave {
if fn == nil {
return nil return nil
} }
for _, fn := range c.Options().AfterSave {
if err := fn(ctx, c); err != nil { if err := fn(ctx, c); err != nil {
c.Options().Logger.Errorf(ctx, "%s AfterSave err: %v", c.String(), err) c.Options().Logger.Errorf(ctx, "%s AfterSave err: %v", c.String(), err)
if !c.Options().AllowFail { if !c.Options().AllowFail {
@ -186,10 +186,10 @@ var (
} }
// DefaultBeforeInit default func that runs befora config Init // DefaultBeforeInit default func that runs befora config Init
DefaultBeforeInit = func(ctx context.Context, c Config) error { DefaultBeforeInit = func(ctx context.Context, c Config) error {
if c.Options().BeforeInit == nil { for _, fn := range c.Options().BeforeInit {
if fn == nil {
return nil return nil
} }
for _, fn := range c.Options().BeforeInit {
if err := fn(ctx, c); err != nil { if err := fn(ctx, c); err != nil {
c.Options().Logger.Errorf(ctx, "%s BeforeInit err: %v", c.String(), err) c.Options().Logger.Errorf(ctx, "%s BeforeInit err: %v", c.String(), err)
if !c.Options().AllowFail { if !c.Options().AllowFail {
@ -201,10 +201,10 @@ var (
} }
// DefaultAfterInit default func that runs after config Init // DefaultAfterInit default func that runs after config Init
DefaultAfterInit = func(ctx context.Context, c Config) error { DefaultAfterInit = func(ctx context.Context, c Config) error {
if c.Options().AfterInit == nil { for _, fn := range c.Options().AfterSave {
if fn == nil {
return nil return nil
} }
for _, fn := range c.Options().AfterSave {
if err := fn(ctx, c); err != nil { if err := fn(ctx, c); err != nil {
c.Options().Logger.Errorf(ctx, "%s AfterInit err: %v", c.String(), err) c.Options().Logger.Errorf(ctx, "%s AfterInit err: %v", c.String(), err)
if !c.Options().AllowFail { if !c.Options().AllowFail {