status

package
v0.253.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package status provides utilities for status and errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownstreamError

func DownstreamError(err error) error

DownstreamError creates a new error with status SourceDownstream.

func DownstreamErrorf

func DownstreamErrorf(format string, a ...any) error

DownstreamErrorf creates a new error with status SourceDownstream and formats according to a format specifier and returns the string as a value that satisfies error.

func InitSource

func InitSource(ctx context.Context) context.Context

InitSource initialize the source for the context.

func IsCancelledError

func IsCancelledError(err error) bool

InCancelledError returns true if err is context.Canceled or is gRPC status Canceled.

func IsDownstreamError

func IsDownstreamError(err error) bool

IsDownstreamError return true if provided error is an error with downstream source or a timeout error or a cancelled error.

func IsDownstreamHTTPError

func IsDownstreamHTTPError(err error) bool

IsDownstreamHTTPError return true if provided error is an error with downstream source or a HTTP timeout error or a cancelled error or a connection reset/refused error or dns not found error.

func WithDownstreamSource

func WithDownstreamSource(ctx context.Context) error

WithDownstreamSource mutates the provided context by setting the source to SourceDownstream. If the provided context does not have a source, the context will not be mutated and an error returned. This means that InitSource has to be called before this function.

func WithSource

func WithSource(ctx context.Context, s Source) error

WithSource mutates the provided context by setting the source to s. If the provided context does not have a source, the context will not be mutated and an error returned. This means that InitSource has to be called before this function.

Types

type Source

type Source string

Source type defines the status source.

const (
	// SourcePlugin status originates from plugin.
	SourcePlugin Source = "plugin"

	// SourceDownstream status originates from downstream service.
	SourceDownstream Source = "downstream"

	// DefaultSource is the default [Source] that should be used when it is not explicitly set.
	DefaultSource Source = SourcePlugin
)

func SourceFromContext

func SourceFromContext(ctx context.Context) Source

SourceFromContext returns the source stored in the context. If no source is stored in the context, DefaultSource is returned.

func SourceFromHTTPStatus

func SourceFromHTTPStatus(statusCode int) Source

ErrorSourceFromStatus returns a Source based on provided HTTP status code.

func (Source) IsValid

func (s Source) IsValid() bool

IsValid return true if es is SourceDownstream or SourcePlugin.

func (Source) String

func (s Source) String() string

String returns the string representation of s. If s is not valid, DefaultSource is returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL