From 98eceb98422c283d87185620b038aa20bfb5648c Mon Sep 17 00:00:00 2001 From: zhouchenh <37189091+zhouchenh@users.noreply.github.com> Date: Tue, 22 Jun 2021 13:50:31 +0800 Subject: [PATCH] feature: Added a new ValueSource ValueGenerator. Signed-off-by: zhouchenh <37189091+zhouchenh@users.noreply.github.com> --- descriptor.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/descriptor.go b/descriptor.go index 55c7983..da00118 100644 --- a/descriptor.go +++ b/descriptor.go @@ -97,6 +97,8 @@ type ( DefaultValue struct { Value interface{} } + + ValueGenerator func(i interface{}) (object interface{}, ok bool) ) var Root = RootAsPath{} @@ -265,6 +267,11 @@ func (dv DefaultValue) ExtractObject(interface{}) (object interface{}, ok bool) return dv.Value, true } +func (vg ValueGenerator) ExtractObject(data interface{}) (object interface{}, ok bool) { + object, ok = vg(data) + return +} + func (vs ValueSources) ExtractObject(data interface{}) (object interface{}, ok bool) { for _, valueSource := range vs { if valueSource == nil {