Documentation ¶
Overview ¶
Package metadata provides an API that allows plugins to add metadata to the context. Each metadata is stored under a label that has the form <plugin>/<name>. Each metadata is returned as a Func. When Func is called the metadata is returned. If Func is expensive to execute it is its responsibility to provide some form of caching. During the handling of a query it is expected the metadata stays constant.
Basic example:
Implement the Provider interface for a plugin:
func (p P) Metadata(ctx context.Context, state request.Request) context.Context { cached := "" f := func() string { if cached != "" { return cached } cached = expensiveFunc() return cached } metadata.SetValueFunc(ctx, "test/something", f) return ctx }
Check the metadata from another plugin:
// ... valueFunc := metadata.ValueFunc(ctx, "test/something") value := valueFunc() // use 'value'
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsLabel ¶
IsLabel checks that the provided name is a valid label name, i.e. two words separated by a slash.
Types ¶
type Func ¶
type Func func() string
Func is the type of function in the metadata, when called they return the value of the label.
type Metadata ¶
Metadata implements collecting metadata information from all plugins that implement the Provider interface.
type Provider ¶
type Provider interface { // Metadata adds metadata to the context and returns a (potentially) new context. // Note: this method should work quickly, because it is called for every request // from the metadata plugin. Metadata(ctx context.Context, state request.Request) context.Context }
Provider interface needs to be implemented by each plugin willing to provide metadata information for other plugins.