before/after config stuff handled by implementations

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-12-18 03:43:00 +03:00
parent d5e8eaee2f
commit 6db6cf6ef0

View File

@ -90,6 +90,12 @@ func (c *vaultConfig) Init(opts ...config.Option) error {
} }
func (c *vaultConfig) Load(ctx context.Context) error { func (c *vaultConfig) Load(ctx context.Context) error {
for _, fn := range c.opts.BeforeLoad {
if err := fn(ctx, c); err != nil {
return err
}
}
//_, version, err := getKVinfo(c.cli, c.path) //_, version, err := getKVinfo(c.cli, c.path)
//if err != nil { //if err != nil {
// return err // return err
@ -121,10 +127,32 @@ func (c *vaultConfig) Load(ctx context.Context) error {
return err return err
} }
return c.opts.Codec.Unmarshal(data, c.opts.Struct) if err = c.opts.Codec.Unmarshal(data, c.opts.Struct); err != nil {
return err
}
for _, fn := range c.opts.AfterLoad {
if err := fn(ctx, c); err != nil {
return err
}
}
return nil
} }
func (c *vaultConfig) Save(ctx context.Context) error { func (c *vaultConfig) Save(ctx context.Context) error {
for _, fn := range c.opts.BeforeSave {
if err := fn(ctx, c); err != nil {
return err
}
}
for _, fn := range c.opts.AfterSave {
if err := fn(ctx, c); err != nil {
return err
}
}
return nil return nil
} }