-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
- Loading branch information
1 parent
ad54eab
commit 7b1ae4d
Showing
9 changed files
with
57 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package template | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/jmespath-community/go-jmespath/pkg/binding" | ||
) | ||
|
||
type resolverFunc = func() (interface{}, error) | ||
|
||
type lazyBinding struct { | ||
resolver resolverFunc | ||
} | ||
|
||
func (b *lazyBinding) Value() (interface{}, error) { | ||
return b.resolver() | ||
} | ||
|
||
func NewLazyBinding(resolver resolverFunc) binding.Binding { | ||
binding := &lazyBinding{} | ||
lock := &sync.Mutex{} | ||
binding.resolver = func() (interface{}, error) { | ||
lock.Lock() | ||
defer lock.Unlock() | ||
value, err := resolver() | ||
binding.resolver = func() (interface{}, error) { | ||
return value, err | ||
} | ||
return binding.resolver() | ||
} | ||
return binding | ||
} | ||
|
||
func NewLazyBindingWithValue(value interface{}) binding.Binding { | ||
return NewLazyBinding(func() (interface{}, error) { | ||
return value, nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters