Merge pull request 'config: fix Default funcs' (#192) from config-fix into v3

Reviewed-on: #192
This commit is contained in:
Василий Толстов 2023-03-15 22:53:21 +03:00
commit 0c78873277

View File

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