thrift

package
v0.0.0-...-cda3813 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

thrift

This package heavily inspired by Go-Kit gRPC Transport

Documentation

Overview

Package thrift provides a Thrift binding for endpoints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithResponseMeta

func ContextWithResponseMeta(ctx context.Context, v *Metadata) context.Context

ContextWithResponseMeta returns a copy of ctx with v set as the response metadata value.

func ExtractResponseMeta

func ExtractResponseMeta(next thrift.TClient) thrift.TClient

ExtractResponseMeta is a Thrift middleware that retrieves the Thrift response metadata and injects it into the context. This is useful for passing along metadata from the Thrift response to other parts of the application that have access to the context.

Types

type ClientFinalizerFunc

type ClientFinalizerFunc func(ctx context.Context, err error)

ClientFinalizerFunc can be used to perform work at the end of a client Thrift request, after the response is returned. The principal intended use is for error logging. Additional response parameters are provided in the context under keys with the ContextKeyResponse prefix. NOTE: err may be nil. There maybe also no additional response parameters depending on when an error occurs.

type ClientRequestFunc

type ClientRequestFunc func(ctx context.Context, md *Metadata) context.Context

ClientRequestFunc may take information from context and use it to construct headers to be transported to the server. ClientRequestFuncs are executed after creating the request but prior to sending the Thrift request to the server.

func SetRequestHeader

func SetRequestHeader(key, val string) ClientRequestFunc

SetRequestHeader returns a ClientRequestFunc that sets the specified header key-value pair.

type ClientResponseFunc

type ClientResponseFunc func(ctx context.Context, md Metadata) context.Context

ClientResponseFunc may take information from a Thrift response metadata and make the responses available for consumption. ClientResponseFuncs are only executed in clients, after a request has been made, but prior to it being decoded.

type Header interface {
	// Get returns the value associated with the given key. If the key is
	// present in the header, the value (which may be empty) is returned.
	// Otherwise, the returned value will be the empty string. The ok return
	// value reports whether the value is explicitly set in the header.
	Get(key string) (value string, ok bool)

	// Set sets the header entry associated with key to the value.
	Set(key, value string)

	// Keys returns the keys of the header.
	Keys() []string
}

Header contains methods for managing Thrift headers.

type HeaderContext

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

HeaderContext represents a Thrift header backed by a context.

func NewHeaderContext

func NewHeaderContext(ctx context.Context) *HeaderContext

NewHeaderContext creates and returns a new instance of HeaderContext with provider context.

func (*HeaderContext) Get

func (h *HeaderContext) Get(key string) (string, bool)

Get returns the value associated with the given key. If the key is present in the header, the value (which may be empty) is returned. Otherwise, the returned value will be the empty string. The ok return value reports whether the value is explicitly set in the header.

func (*HeaderContext) Keys

func (h *HeaderContext) Keys() []string

Keys returns a slice containing all the keys present in the context's headers.

func (*HeaderContext) Set

func (h *HeaderContext) Set(string, string)

Set is a no-op method for HeaderContext, implementing the Header interface. NOTE: Cannot set to HeaderContext.

type HeaderMap

type HeaderMap map[string]string

HeaderMap represents a Thrift header backed by a map.

func (HeaderMap) Get

func (h HeaderMap) Get(key string) (value string, ok bool)

Get returns the value associated with the given key. If the key is present in the header, the value (which may be empty) is returned. Otherwise, the returned value will be the empty string. The ok return value reports whether the value is explicitly set in the header.

func (HeaderMap) Keys

func (h HeaderMap) Keys() []string

Keys returns the keys of the header.

func (HeaderMap) Set

func (h HeaderMap) Set(key string, value string)

Set sets the value associated with the given key in the header map.

type Metadata

type Metadata struct {
	// The headers in the request or response.
	Header Header
}

Metadata represents the metadata attached to the request or response.

func ResponseMetaFromContext

func ResponseMetaFromContext(ctx context.Context) *Metadata

ResponseMetaFromContext returns the response metadata from ctx.

type ServerFinalizerFunc

type ServerFinalizerFunc func(ctx context.Context, err error)

ServerFinalizerFunc can be used to perform work at the end of an gRPC request, after the response has been written to the client.

type ServerRequestFunc

type ServerRequestFunc func(ctx context.Context, md Metadata) context.Context

ServerRequestFunc may extracts information from the request context and associates it with a new user-defined key. ServerRequestFunc allows for unified access these data in service or endpoint middleware, similar to other transport types (such as gRPC, HTTP, ...). ServerRequestFuncs are executed prior to invoking the endpoint.

func SetRequestContext

func SetRequestContext(ctxKey any, headerKey string) ServerRequestFunc

SetRequestContext returns a ServerRequestFunc that associates a value from the request context with a new user-defined key.

type ServerResponseFunc

type ServerResponseFunc func(ctx context.Context, md *Metadata) context.Context

ServerResponseFunc may take information from a request context and use it to manipulate the gRPC response metadata headers and trailers. ResponseFuncs are only executed in servers, after invoking the endpoint but prior to writing a response.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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