blaze

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

README

blaze

The blaze rpc framework

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GrpcCodeFromErrorType added in v0.0.5

func GrpcCodeFromErrorType(err error) codes.Code

GrpcCodeFromErrorType converts a blaze error into a grpc error code

func IsError

func IsError(err error) bool

IsError checks if the passed error is a blaze error

func NewHTTPRequest added in v0.0.2

func NewHTTPRequest(ctx context.Context, url string, reqBody io.Reader, contentType string, version string) (*http.Request, error)

NewHTTPRequest creates a httprequest for a client, adding common headers.

func ServerBadRouteError

func ServerBadRouteError(msg string, method, url string) error

ServerBadRouteError is used when the blaze server cannot route a request

func ServerEnsurePanicResponses

func ServerEnsurePanicResponses(ctx context.Context, resp http.ResponseWriter, log logr.Logger)

ServerEnsurePanicResponses esure panic responses

func ServerHTTPStatusFromErrorType

func ServerHTTPStatusFromErrorType(err error) int

ServerHTTPStatusFromErrorType maps a blaze error type into a similar HTTP response status. It is used by the blaze server handler to set the HTTP response status code. Returns 0 if the error is not a blaze error.

func ServerInvalidRequestError

func ServerInvalidRequestError(argument string, validationMsg string, method, url string) error

ServerInvalidRequestError is used when the server is called with an invalid argument

func ServerWriteError

func ServerWriteError(ctx context.Context, resp http.ResponseWriter, err error, log logr.Logger)

ServerWriteError writes Blaze errors in the response and triggers hooks.

func UrlBase added in v0.0.2

func UrlBase(addr string) string

UrlBase helps ensure that addr specifies a scheme. If it is unparsable as a URL, it returns addr unchanged.

func WithoutRedirects added in v0.0.2

func WithoutRedirects(in *http.Client) *http.Client

WithoutRedirects makes sure that the POST request can not be redirected. The standard library will, by default, redirect requests (including POSTs) if it gets a 302 or 303 response, and also 301s in go1.8. It redirects by making a second request, changing the method to GET and removing the body. This produces very confusing error messages, so instead we set a redirect policy that always errors. This stops Go from executing the redirect.

We have to be a little careful in case the user-provided http.Client has its own CheckRedirect policy - if so, we'll run through that policy first.

Because this requires modifying the http.Client, we make a new copy of the client and return it.

Types

type AbortedErrorType

type AbortedErrorType struct{}

AbortedErrorType indicates the operation was aborted, typically due to a concurrency issue like sequencer check failures, transaction aborts, etc.

func (*AbortedErrorType) Error

func (e *AbortedErrorType) Error() string

type AlreadyExistsErrorType

type AlreadyExistsErrorType struct{}

AlreadyExistsErrorType means an attempt to create an entity failed because one already exists

func (*AlreadyExistsErrorType) Error

func (e *AlreadyExistsErrorType) Error() string

type BadRouteErrorType

type BadRouteErrorType struct{}

BadRouteErrorType means that the requested URL path wasn't routable to a blaze service and method. This is returned by the generated server, and usually shouldn't be returned by applications. Instead, applications should use NotFound or Unimplemented.

func (*BadRouteErrorType) Error

func (e *BadRouteErrorType) Error() string

type CanceledErrorType

type CanceledErrorType struct{}

CanceledErrorType indicates the operation was cancelled (typically by the caller).

func (*CanceledErrorType) Error

func (e *CanceledErrorType) Error() string

type ClientOption added in v0.0.2

type ClientOption func(*ClientOptions)

ClientOption is a functional option for extending a Blaze client.

type ClientOptions added in v0.0.2

type ClientOptions struct {
	// Trace implementation for distributed tracing
	Trace blazetrace.ClientTracer
}

ClientOptions encapsulate the configurable parameters on a Blaze client.

type DataLossErrorType

type DataLossErrorType struct{}

DataLossErrorType indicates unrecoverable data loss or corruption.

func (*DataLossErrorType) Error

func (e *DataLossErrorType) Error() string

type DeadlineExceededErrorType

type DeadlineExceededErrorType struct{}

DeadlineExceededErrorType means operation expired before completion. For operations that change the state of the system, this error may be returned even if the operation has completed successfully (timeout).

func (*DeadlineExceededErrorType) Error

func (e *DeadlineExceededErrorType) Error() string

type Error

type Error interface {
	// Type returns the type of the error
	Type() string
	// Msg returns a human-readable, unstructured messages describing the error.
	Msg() string

	// WithMeta returns a copy of the Error with the given key-value pair attached
	// as metadata. If the key is already set, it is overwritten.
	WithMeta(key string, val string) Error

	// Meta returns the stored value for the given key. If the key has no set
	// value, Meta returns an empty string. There is no way to distinguish between
	// an unset value and an explicit empty string.
	Meta(key string) string

	// MetaMap returns a copy of the complete key-value metadata map stored on the error.
	MetaMap() map[string]string

	// Error returns a string of the form "blaze error <Type>: <Msg>"
	Error() string

	//Unwrap returns the wrapped error
	Unwrap() error
}

Error represents an error in a Blaze service call.

func ErrorAborted

func ErrorAborted(msg string) Error

ErrorAborted constructs a aborted error

func ErrorAlreadyExists

func ErrorAlreadyExists(msg string) Error

ErrorAlreadyExists constructs a already exists error

func ErrorBadRoute

func ErrorBadRoute(msg string) Error

ErrorBadRoute constructs bad route error

func ErrorCanceled

func ErrorCanceled(msg string) Error

ErrorCanceled constructs a canceled error

func ErrorDataLoss

func ErrorDataLoss(msg string) Error

ErrorDataLoss constructs a data loss error

func ErrorDeadlineExeeded

func ErrorDeadlineExeeded(msg string) Error

ErrorDeadlineExeeded constructs a canceled error

func ErrorFailedPrecondition

func ErrorFailedPrecondition(msg string) Error

ErrorFailedPrecondition constructs a failed precondition error

func ErrorFromResponse added in v0.0.2

func ErrorFromResponse(resp *http.Response) Error

ErrorFromResponse builds a blaze.Error from a non-200 HTTP response. If the response has a valid serialized Blaze error, then it's returned. If not, the response status code is used to generate a similar Blaze error. See blazeErrorFromIntermediary for more info on intermediary errors.

func ErrorInternal

func ErrorInternal(msg string) Error

ErrorInternal When some invariants expected by the underlying system have been broken. In other words, something bad happened in the library or backend service. Do not confuse with HTTP Internal Server Error; an Internal error could also happen on the client code, i.e. when parsing a server response.

func ErrorInternalWith

func ErrorInternalWith(err error, msg string) Error

ErrorInternalWith When some invariants expected by the underlying system have been broken. In other words, something bad happened in the library or backend service. Do not confuse with HTTP Internal Server Error; an Internal error could also happen on the client code, i.e. when parsing a server response. Wraps an other error for more information

func ErrorInvalidArgument

func ErrorInvalidArgument(argument string, validationMsg string) Error

ErrorInvalidArgument constructs invalid argument error

func ErrorJSONToError added in v0.0.2

func ErrorJSONToError(j ErrorJSON) (Error, error)

ErrorJSONToError converts a ErrorJSON struct into an Error

func ErrorMalformed

func ErrorMalformed(msg string) Error

ErrorMalformed constructs a malformed error

func ErrorNotFound

func ErrorNotFound(msg string) Error

ErrorNotFound constructs a canceled error

func ErrorOutOfRange

func ErrorOutOfRange(msg string) Error

ErrorOutOfRange constructs a out of range error

func ErrorPermissionDenied

func ErrorPermissionDenied(msg string) Error

ErrorPermissionDenied constructs a permission denied error

func ErrorRequiredArgument

func ErrorRequiredArgument(argument string) Error

ErrorRequiredArgument is a more specific constructor for ErrorInvalidArgument. Should be used when the argument is required (expected to have a non-zero value).

func ErrorResourceExhausted

func ErrorResourceExhausted(msg string) Error

ErrorResourceExhausted constructs a resource exhousted error

func ErrorUnauthenticated

func ErrorUnauthenticated(msg string) Error

ErrorUnauthenticated constructs a unauthenticated error

func ErrorUnavailable

func ErrorUnavailable(msg string) Error

ErrorUnavailable constructs an unavailable error

func ErrorUnimplemented

func ErrorUnimplemented(msg string) Error

ErrorUnimplemented constructs an unimplemented error

func ErrorUnknown

func ErrorUnknown(msg string) Error

ErrorUnknown constructs a Unknown error

func NewError

func NewError(err error, msg string) Error

NewError is the generic constructor for a blaze.Error. The error must be one of the valid predefined ones in errors.go, otherwise it will be converted to an error {type: Internal, msg: "invalid error type {{code}}"}. If you need to add metadata, use .WithMeta(key, value) method after building the error.

type ErrorJSON added in v0.0.2

type ErrorJSON struct {
	Code string            `json:"code"`
	Msg  string            `json:"msg"`
	Type string            `json:"blaze_type"`
	Meta map[string]string `json:"meta,omitempty"`
}

ErrorJSON is JSON serialization for blaze errors

func ErrorToErrorJSON added in v0.0.2

func ErrorToErrorJSON(e Error) (ErrorJSON, error)

ErrorToErrorJSON concerts a Error into a ErrorJSON struct

type FailedPreconditionErrorType

type FailedPreconditionErrorType struct{}

FailedPreconditionErrorType indicates operation was rejected because the system is not in a state required for the operation's execution. For example, doing an rmdir operation on a directory that is non-empty, or on a non-directory object, or when having conflicting read-modify-write on the same resource.

func (*FailedPreconditionErrorType) Error

type HTTPClient added in v0.0.2

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is the interface used by generated clients to send HTTP requests. It is fulfilled by *(net/http).Client, which is sufficient for most users. Users can provide their own implementation for special retry policies.

HTTPClient implementations should not follow redirects. Redirects are automatically disabled if *(net/http).Client is passed to client constructors. See the withoutRedirects function in this file for more details.

type InternalErrorType

type InternalErrorType struct {
	// contains filtered or unexported fields
}

InternalErrorType error is an error produced by a downstream dependency of blaze

func (*InternalErrorType) Error

func (e *InternalErrorType) Error() string

func (*InternalErrorType) Unwrap

func (e *InternalErrorType) Unwrap() error

Unwrap implements the wrappable error

type InvalidArgumentErrorType

type InvalidArgumentErrorType struct{}

InvalidArgumentErrorType indicates client specified an invalid argument. It indicates arguments that are problematic regardless of the state of the system (i.e. a malformed file name, required argument, number out of range, etc.).

func (*InvalidArgumentErrorType) Error

func (e *InvalidArgumentErrorType) Error() string

type MalformedErrorType

type MalformedErrorType struct{}

MalformedErrorType indicates an error occured while decoding the client's request. This means that the message was encoded improperly, or that there is an disagreement in message format between client and server

func (*MalformedErrorType) Error

func (e *MalformedErrorType) Error() string

type NotFoundErrorType

type NotFoundErrorType struct{}

NotFoundErrorType indicates a common NotFound error

func (*NotFoundErrorType) Error

func (e *NotFoundErrorType) Error() string

type OutOfRangeErrorType

type OutOfRangeErrorType struct{}

OutOfRangeErrorType means operation was attempted past the valid range. For example, seeking or reading past end of a paginated collection.

Unlike InvalidArgument, this error indicates a problem that may be fixed if the system state changes (i.e. adding more items to the collection).

There is a fair bit of overlap between FailedPrecondition and OutOfRange. We recommend using OutOfRange (the more specific error) when it applies so that callers who are iterating through a space can easily look for an OutOfRange error to detect when they are done.

func (*OutOfRangeErrorType) Error

func (e *OutOfRangeErrorType) Error() string

type PermissionDeniedErrorType

type PermissionDeniedErrorType struct{}

PermissionDeniedErrorType indicates the caller does not have permission to execute the specified operation. It must not be used if the caller cannot be identified (Unauthenticated).

func (*PermissionDeniedErrorType) Error

func (e *PermissionDeniedErrorType) Error() string

type ResourceExhaustedErrorType

type ResourceExhaustedErrorType struct{}

ResourceExhaustedErrorType indicates some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space.

func (*ResourceExhaustedErrorType) Error

type Service added in v0.0.4

type Service interface {
	Mux() *chi.Mux
	MountPath() string
}

Service defines the interface of blazeservice

type ServiceOption added in v0.0.4

type ServiceOption func(*ServiceOptions)

ServiceOption is a functional option for extending a Blaze service.

func WithJSONEmitDefaults added in v0.0.3

func WithJSONEmitDefaults(v bool) ServiceOption

WithJSONEmitDefaults makes JSON structs to render fields even if they are empty or the default value

func WithJSONEnumsAsInts added in v0.0.3

func WithJSONEnumsAsInts(v bool) ServiceOption

WithJSONEnumsAsInts makes enums be rendered as ints instead of strings

func WithMux added in v0.0.3

func WithMux(mux *chi.Mux) ServiceOption

WithMux allows to set the chi mux to use by a service

func WithServiceTracer added in v0.0.5

func WithServiceTracer(trace blazetrace.ServiceTracer) ServiceOption

WithServiceTracer replaces the default tracer

type ServiceOptions added in v0.0.4

type ServiceOptions struct {
	// Uses a specific mux instead of chi.NewRouter()
	Mux *chi.Mux
	// Whether to render enum values as integers, as opposed to string values.
	JSONEnumsAsInts bool
	// Whether to render fields with zero values.
	JSONEmitDefaults bool
	// Trace implementation for distributed tracing
	Trace blazetrace.ServiceTracer
}

ServiceOptions encapsulate the configurable parameters on a Blaze service.

type UnauthenticatedErrorType

type UnauthenticatedErrorType struct{}

UnauthenticatedErrorType indicates the request does not have valid authentication credentials for the operation.

func (*UnauthenticatedErrorType) Error

func (e *UnauthenticatedErrorType) Error() string

type UnavailableErrorType

type UnavailableErrorType struct{}

UnavailableErrorType indicates the service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.

func (*UnavailableErrorType) Error

func (e *UnavailableErrorType) Error() string

type UnimplementedErrorType

type UnimplementedErrorType struct{}

UnimplementedErrorType indicates operation is not implemented or not supported/enabled in this service.

func (*UnimplementedErrorType) Error

func (e *UnimplementedErrorType) Error() string

type UnknownErrorType

type UnknownErrorType struct{}

UnknownErrorType For example handling errors raised by APIs that dont return enough error information

func (*UnknownErrorType) Error

func (e *UnknownErrorType) Error() string

Directories

Path Synopsis
cmd
internal
pkg

Jump to

Keyboard shortcuts

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