plugin/template: support metadata (#2958)

* Enable use of metadata in templates

* Update README

* Don't stash away ctx, instead use a new func
This commit is contained in:
John Belamaric
2019-07-03 16:10:56 +01:00
committed by GitHub
parent 2faad5b397
commit 7cf73cc01d
4 changed files with 135 additions and 4 deletions

View File

@@ -82,6 +82,16 @@ func Labels(ctx context.Context) []string {
return nil
}
// ValueFuncs returns the map[string]Func from the context, or nil if it does not exist.
func ValueFuncs(ctx context.Context) map[string]Func {
if metadata := ctx.Value(key{}); metadata != nil {
if m, ok := metadata.(md); ok {
return m
}
}
return nil
}
// ValueFunc returns the value function of label. If none can be found nil is returned. Calling the
// function returns the value of the label.
func ValueFunc(ctx context.Context, label string) Func {