api

package
v1.0.0-alpha.47 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeaderRequestTimeout is an end-to-end request header that indicates the maximum time that a client is
	// prepared to await a response. The value of the header is in seconds. A client is allowed to send fractional
	// values. For ex, 0.1 means 100milliseconds.
	HeaderRequestTimeout = "Request-Timeout"

	HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin"

	HeaderPrefix = "Tigris-"

	HeaderTxID     = "Tigris-Tx-Id"
	HeaderTxOrigin = "Tigris-Tx-Origin"
	SetCookie      = "Set-Cookie"
	Cookie         = "Cookie"
)
View Source
const CollationKey string = "collation"

Variables

View Source
var SupportedCollations = [...]string{
	CaseInsensitive: "ci",
	CaseSensitive:   "cs",
}

Functions

func CodeToString

func CodeToString(c Code) string

CodeToString convert Tigris error code into string representation

func CustomMatcher

func CustomMatcher(key string) (string, bool)

func GetHeader

func GetHeader(ctx context.Context, header string) string

func IsTxSupported

func IsTxSupported(ctx context.Context) bool

func MarshalStatus

func MarshalStatus(status *spb.Status) ([]byte, error)

MarshalStatus marshal status object

func ToGRPCCode

func ToGRPCCode(code Code) codes.Code

ToGRPCCode converts Tigris error code to GRPC code Extended codes converted to 'Unknown' GRPC code

func ToHTTPCode

func ToHTTPCode(code Code) int

ToHTTPCode converts Tigris' code to HTTP status code Used to customize HTTP codes returned by GRPC-gateway

Types

type CollationType

type CollationType uint8
const (
	Undefined CollationType = iota
	CaseInsensitive
	CaseSensitive
)

func ToCollationType

func ToCollationType(userCollation string) CollationType

type CustomDecoder

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

func (CustomDecoder) Decode

func (f CustomDecoder) Decode(dst interface{}) error

type CustomMarshaler

type CustomMarshaler struct {
	JSONBuiltin *runtime.JSONBuiltin
}

CustomMarshaler is a marshaler to customize the response. Currently, it is only used to marshal custom error message otherwise it just uses the inbuilt mux marshaller.

func (*CustomMarshaler) ContentType

func (c *CustomMarshaler) ContentType(v interface{}) string

func (*CustomMarshaler) Marshal

func (c *CustomMarshaler) Marshal(v interface{}) ([]byte, error)

func (*CustomMarshaler) NewDecoder

func (c *CustomMarshaler) NewDecoder(r io.Reader) runtime.Decoder

func (*CustomMarshaler) NewEncoder

func (c *CustomMarshaler) NewEncoder(w io.Writer) runtime.Encoder

func (*CustomMarshaler) Unmarshal

func (c *CustomMarshaler) Unmarshal(data []byte, v interface{}) error

type Metadata

type Metadata struct {
	CreatedAt *time.Time `json:"created_at,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
}

func CreateMDFromResponseMD

func CreateMDFromResponseMD(x *ResponseMetadata) Metadata

type Request

type Request interface {
	proto.Message

	Validator
}

type RequestWithDb

type RequestWithDb interface {
	GetDb() string
}

type RequestWithDbAndCollection

type RequestWithDbAndCollection interface {
	GetDb() string
	GetCollection() string
}

type Response

type Response interface {
	proto.Message
}

type SearchHitMetadata

type SearchHitMetadata struct {
	CreatedAt *time.Time `json:"created_at,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
}

func CreateMDFromSearchMD

func CreateMDFromSearchMD(x *SearchHitMeta) SearchHitMetadata

type TigrisError

type TigrisError struct {
	// Contains Tigris extended error code.
	// Codes upto Code_UNAUTHENTICATED are identical to GRPC error codes
	Code Code `json:"code,omitempty"`
	// A developer-facing error message.
	Message string `json:"message,omitempty"`

	// Contains extended error information.
	// For example retry information.
	Details []proto.Message `json:"details,omitempty"`
}

TigrisError is our Tigris HTTP counterpart of grpc status. All the APIs should use this Error to return as a user facing error. TigrisError will return grpcStatus to the muxer so that grpc client can see grpcStatus as the final output. For HTTP clients see the **MarshalStatus** method where we are returning the response by not the grpc code as that is not needed for HTTP clients.

func Errorf

func Errorf(c Code, format string, a ...interface{}) *TigrisError

Errorf constructs TigrisError

func FromErrorDetails

func FromErrorDetails(e *ErrorDetails) *TigrisError

FromErrorDetails construct TigrisError from the ErrorDetails, which contains extended code, retry information, etc...

func FromStatusError

func FromStatusError(err error) *TigrisError

FromStatusError parses GRPC status from error into TigrisError

func UnmarshalStatus

func UnmarshalStatus(b []byte) *TigrisError

UnmarshalStatus reconstruct TigrisError from HTTP error JSON body

func (*TigrisError) As

func (e *TigrisError) As(i any) bool

As is used by runtime.DefaultHTTPErrorHandler to override HTTP status code

func (*TigrisError) Error

func (e *TigrisError) Error() string

Error to return the underlying error message

func (*TigrisError) GRPCStatus

func (e *TigrisError) GRPCStatus() *status.Status

GRPCStatus converts the TigrisError and return status.Status. This is used to return grpc status to the grpc clients

func (*TigrisError) RetryDelay

func (e *TigrisError) RetryDelay() time.Duration

RetryDelay retrieves retry delay if it's attached to the error

func (*TigrisError) WithDetails

func (e *TigrisError) WithDetails(details ...proto.Message) *TigrisError

WithDetails a helper method for adding details to the TigrisError

func (*TigrisError) WithRetry

func (e *TigrisError) WithRetry(d time.Duration) *TigrisError

WithRetry attached retry information to the error

type Validator

type Validator interface {
	Validate() error
}

Jump to

Keyboard shortcuts

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