config: add conditions #287
@@ -7,8 +7,8 @@ import (
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/google/uuid"
 | 
			
		||||
	"dario.cat/mergo"
 | 
			
		||||
	"github.com/google/uuid"
 | 
			
		||||
	"go.unistack.org/micro/v4/options"
 | 
			
		||||
	mid "go.unistack.org/micro/v4/util/id"
 | 
			
		||||
	rutil "go.unistack.org/micro/v4/util/reflect"
 | 
			
		||||
@@ -40,6 +40,10 @@ func (c *defaultConfig) Init(opts ...options.Option) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *defaultConfig) Load(ctx context.Context, opts ...options.Option) error {
 | 
			
		||||
	if c.opts.SkipLoad != nil && c.opts.SkipLoad(ctx, c) {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := DefaultBeforeLoad(ctx, c); err != nil && !c.opts.AllowFail {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
@@ -292,7 +296,11 @@ func fillValues(valueOf reflect.Value, tname string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *defaultConfig) Save(ctx context.Context, opts ...options.Option) error {
 | 
			
		||||
func (c *defaultConfig) Save(ctx context.Context, _ ...options.Option) error {
 | 
			
		||||
	if c.opts.SkipSave != nil && c.opts.SkipSave(ctx, c) {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := DefaultBeforeSave(ctx, c); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -43,6 +43,10 @@ type Options struct {
 | 
			
		||||
	AfterInit []func(context.Context, Config) error
 | 
			
		||||
	// AllowFail flag to allow fail in config source
 | 
			
		||||
	AllowFail bool
 | 
			
		||||
	// SkipLoad runs only if condition returns true
 | 
			
		||||
	SkipLoad func(context.Context, Config) bool
 | 
			
		||||
	// SkipSave runs only if condition returns true
 | 
			
		||||
	SkipSave func(context.Context, Config) bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewOptions new options struct with filed values
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user