kitty

package module
v0.0.0-...-221cc1b Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2016 License: MIT Imports: 14 Imported by: 4

README

kitty

Tiny go-kit toolbox

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// APIInternal indicates an unexpected internal error.
	APIInternal = APIError{
		Status:      500,
		Description: "An internal error occured. Please retry later.",
		ErrorCode:   "INTERNAL_ERROR",
		Params:      make(map[string]interface{}),
	}
	// APIUnavailable indicates that an unexpected error happened during
	// the domain execution (from go-kit). Probably caused by an overload.
	APIUnavailable = APIError{
		Status:      503,
		Description: "The service is currently unavailable. Please retry later.",
		ErrorCode:   "SERVICE_UNAVAILABLE",
		Params:      make(map[string]interface{}),
	}
	// APIBodyDecoding indicates that the request body could not be decoded (bad syntax).
	APIBodyDecoding = APIError{
		Status:      400,
		Description: "Could not decode the JSON request.",
		ErrorCode:   "BODY_DECODING_ERROR",
		Params:      make(map[string]interface{}),
	}
	// APIQueryParam indicates that an expected query parameter is missing.
	APIQueryParam = APIError{
		Status:      400,
		Description: "Missing query parameter.",
		ErrorCode:   "QUERY_PARAM_ERROR",
		Params:      make(map[string]interface{}),
	}
	// APIValidation indicates that some received parameters are invalid.
	APIValidation = APIError{
		Status:      400,
		Description: "The parameters validation failed.",
		ErrorCode:   "VALIDATION_ERROR",
		Params:      make(map[string]interface{}),
	}
	// APIUnauthorized indicates that the user does not have a valid associated session.
	APIUnauthorized = APIError{
		Status:      401,
		Description: "Authorization Required.",
		ErrorCode:   "AUTHORIZATION_REQUIRED",
		Params:      make(map[string]interface{}),
	}
	// APIForbidden indicates that the user has a valid session but he is missing some permissions.
	APIForbidden = APIError{
		Status:      403,
		Description: "The specified resource was not found or you don't have sufficient permissions.",
		ErrorCode:   "FORBIDDEN",
		Params:      make(map[string]interface{}),
	}
)

Functions

func EndpointTracingMiddleware

func EndpointTracingMiddleware(next endpoint.Endpoint) endpoint.Endpoint

EndpointTracingMiddleware traces unexpected errors at the endpoint level.

func FromGRPCRequest

func FromGRPCRequest(tracer stdopentracing.Tracer, operationName string, logger log.Logger) grpctransport.RequestFunc

FromGRPCRequest returns a grpc RequestFunc that tries to join with an OpenTracing trace found in `req` and starts a new Span called `operationName` accordingly. If no trace could be found in `req`, the Span will be a trace root. The Span is incorporated in the returned Context and can be retrieved with opentracing.SpanFromContext(ctx).

func FromHTTPRequest

func FromHTTPRequest(tracer stdopentracing.Tracer, operationName string, logger log.Logger) httptransport.RequestFunc

FromHTTPRequest returns an http RequestFunc that tries to join with an OpenTracing trace found in `req` and starts a new Span called `operationName` accordingly. If no trace could be found in `req`, the Span will be a trace root. The Span is incorporated in the returned Context and can be retrieved with opentracing.SpanFromContext(ctx).

func GRPCFinish

func GRPCFinish() grpctransport.ResponseFunc

GRPCFinish finishes a span if a trace could be found.

func ToGRPCRequest

func ToGRPCRequest(tracer stdopentracing.Tracer, logger log.Logger) grpctransport.RequestFunc

ToGRPCRequest returns a grpc RequestFunc that injects an OpenTracing Span found in `ctx` into the grpc Metadata. If no such Span can be found, the RequestFunc is a noop.

func ToHTTPResponse

func ToHTTPResponse(tracer stdopentracing.Tracer, logger log.Logger) httptransport.ServerResponseFunc

ToHTTPResponse returns a http ServerResponseFunc that injects an OpenTracing Span found in `ctx` in the response HTTP header. Typicaly useful for tracing using subrequests. eg. Nginx auth subrequests.

func TraceAPIErrorAndFinish

func TraceAPIErrorAndFinish(ctx context.Context, header http.Header, err APIError)

TraceAPIErrorAndFinish traces an APIError response and finishes the span if a trace could be found.

func TraceError

func TraceError(ctx context.Context, err error)

TraceError traces an error into an 'error' tag that appears red on Zipkin. It is typically used to show that something unexpected happened. It also tags the stacktrace if it could be found.

func TraceStatusAndFinish

func TraceStatusAndFinish(ctx context.Context, header http.Header, status int)

TraceStatusAndFinish traces a HTTP response and finishes the span if a trace could be found.

func TransportErrorEncoder

func TransportErrorEncoder(ctx context.Context, err error, w http.ResponseWriter)

TransportErrorEncoder offers a standardized way of handling transport errors. It responds with the appropriate APIError and traces it.

func WithErrBodyDecoding

func WithErrBodyDecoding(err error) error

WithErrBodyDecoding adds a errBodyDecodingBehavior to the given error.

func WithErrQueryParam

func WithErrQueryParam(err error, key string) error

WithErrQueryParam adds a errQueryParamBehavior to the given error.

Types

type APIError

type APIError struct {
	// The status code.
	Status int `json:"status"`
	// The description of the API error.
	Description string `json:"description"`
	// The token uniquely identifying the API error.
	ErrorCode string `json:"errorCode"`
	// Additional infos.
	Params map[string]interface{} `json:"params,omitempty"`
}

APIError defines a standard format for API errors.

Jump to

Keyboard shortcuts

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