|
|
@ -3,6 +3,8 @@ package pluginrequestmeta |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"context" |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// StatusSource is an enum-like string value representing the source of a
|
|
|
|
// StatusSource is an enum-like string value representing the source of a
|
|
|
@ -14,16 +16,19 @@ const ( |
|
|
|
StatusSourceDownstream StatusSource = "downstream" |
|
|
|
StatusSourceDownstream StatusSource = "downstream" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DefaultStatusSource is the default StatusSource that should be used when it is not explicitly set by the plugin.
|
|
|
|
|
|
|
|
const DefaultStatusSource StatusSource = StatusSourcePlugin |
|
|
|
|
|
|
|
|
|
|
|
type statusSourceCtxKey struct{} |
|
|
|
type statusSourceCtxKey struct{} |
|
|
|
|
|
|
|
|
|
|
|
// StatusSourceFromContext returns the plugin request status source stored in the context.
|
|
|
|
// StatusSourceFromContext returns the plugin request status source stored in the context.
|
|
|
|
// If no plugin request status source is stored in the context, [StatusSourcePlugin] is returned.
|
|
|
|
// If no plugin request status source is stored in the context, [DefaultStatusSource] is returned.
|
|
|
|
func StatusSourceFromContext(ctx context.Context) StatusSource { |
|
|
|
func StatusSourceFromContext(ctx context.Context) StatusSource { |
|
|
|
value, ok := ctx.Value(statusSourceCtxKey{}).(*StatusSource) |
|
|
|
value, ok := ctx.Value(statusSourceCtxKey{}).(*StatusSource) |
|
|
|
if ok { |
|
|
|
if ok { |
|
|
|
return *value |
|
|
|
return *value |
|
|
|
} |
|
|
|
} |
|
|
|
return StatusSourcePlugin |
|
|
|
return DefaultStatusSource |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// WithStatusSource sets the plugin request status source for the context.
|
|
|
|
// WithStatusSource sets the plugin request status source for the context.
|
|
|
@ -42,3 +47,13 @@ func WithDownstreamStatusSource(ctx context.Context) error { |
|
|
|
*v = StatusSourceDownstream |
|
|
|
*v = StatusSourceDownstream |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// StatusSourceFromPluginErrorSource takes an error source returned by a plugin and returns the corresponding
|
|
|
|
|
|
|
|
// StatusSource. If the provided value is a zero-value (i.e.: the plugin did not set it), the function returns
|
|
|
|
|
|
|
|
// DefaultStatusSource.
|
|
|
|
|
|
|
|
func StatusSourceFromPluginErrorSource(pluginErrorSource backend.ErrorSource) StatusSource { |
|
|
|
|
|
|
|
if pluginErrorSource == "" { |
|
|
|
|
|
|
|
return DefaultStatusSource |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return StatusSource(pluginErrorSource) |
|
|
|
|
|
|
|
} |
|
|
|