Documentation ¶
Index ¶
- Constants
- func AllBackwardValuesToSend(ctx context.Context) (m map[string]string)
- func CGIVariableToHTTPHeader(key string) string
- func CountPersistentValues(ctx context.Context) int
- func CountValues(ctx context.Context) int
- func DelPersistentValue(ctx context.Context, k string) context.Context
- func DelValue(ctx context.Context, k string) context.Context
- func FromHTTPHeader(ctx context.Context, h HTTPHeaderCarrier) context.Context
- func GetAllBackwardValues(ctx context.Context) map[string]string
- func GetAllPersistentValues(ctx context.Context) (m map[string]string)
- func GetAllValues(ctx context.Context) (m map[string]string)
- func GetBackwardValue(ctx context.Context, key string) (val string, ok bool)
- func GetBackwardValueToSend(ctx context.Context, key string) (val string, ok bool)
- func GetPersistentValue(ctx context.Context, k string) (v string, ok bool)
- func GetValue(ctx context.Context, k string) (v string, ok bool)
- func GetValueToMap(ctx context.Context, m map[string]string, keys ...string)
- func HTTPHeaderToCGIVariable(key string) string
- func HasMetaInfo(ctx context.Context) bool
- func RangePersistentValues(ctx context.Context, f func(k, v string) bool)
- func RangeValues(ctx context.Context, f func(k, v string) bool)
- func RecvAllBackwardValues(ctx context.Context) (m map[string]string)
- func RecvBackwardValue(ctx context.Context, key string) (val string, ok bool)
- func SaveMetaInfoToMap(ctx context.Context, m map[string]string)
- func SendBackwardValue(ctx context.Context, key, val string) (ok bool)
- func SendBackwardValues(ctx context.Context, kvs ...string) (ok bool)
- func SendBackwardValuesFromMap(ctx context.Context, kvs map[string]string) (ok bool)
- func SetBackwardValue(ctx context.Context, key, val string) (ok bool)
- func SetBackwardValues(ctx context.Context, kvs ...string) (ok bool)
- func SetBackwardValuesFromMap(ctx context.Context, kvs map[string]string) (ok bool)
- func SetMetaInfoFromMap(ctx context.Context, m map[string]string) context.Context
- func ToHTTPHeader(ctx context.Context, h HTTPHeaderSetter)
- func TransferForward(ctx context.Context) context.Context
- func WithBackwardValues(ctx context.Context) context.Context
- func WithBackwardValuesToSend(ctx context.Context) context.Context
- func WithPersistentValue(ctx context.Context, k, v string) context.Context
- func WithPersistentValues(ctx context.Context, kvs ...string) context.Context
- func WithValue(ctx context.Context, k, v string) context.Context
- func WithValues(ctx context.Context, kvs ...string) context.Context
- type HTTPHeader
- type HTTPHeaderCarrier
- type HTTPHeaderSetter
Constants ¶
const ( HTTPPrefixTransient = "rpc-transit-" HTTPPrefixPersistent = "rpc-persist-" HTTPPrefixBackward = "rpc-backward-" )
HTTP header prefixes.
const ( PrefixPersistent = "RPC_PERSIST_" PrefixTransient = "RPC_TRANSIT_" PrefixTransientUpstream = "RPC_TRANSIT_UPSTREAM_" PrefixBackward = "RPC_BACKWARD_" PrefixBackwardDownstream = "RPC_BACKWARD_DOWNSTREAM_" )
The prefix listed below may be used to tag the types of values when there is no context to carry them.
Variables ¶
This section is empty.
Functions ¶
func AllBackwardValuesToSend ¶
AllBackwardValuesToSend retrieves all key-values pairs set by `SendBackwardValue` or `SendBackwardValues` from the given context. This function is designed for frameworks, common developers should not use it.
func CGIVariableToHTTPHeader ¶
CGIVariableToHTTPHeader converts a CGI variable into an HTTP header key. For example, `ABC_DEF` will be converted to `abc-def`.
func CountPersistentValues ¶
CountPersistentValues counts the length of persisten KV pairs
func CountValues ¶
CountValues counts the length of transient KV pairs
func DelPersistentValue ¶
DelPersistentValue deletes a persistent key/value from the current context. Since empty string value is not valid, we could just set the value to be empty.
func DelValue ¶
DelValue deletes a key/value from the current context. Since empty string value is not valid, we could just set the value to be empty.
func FromHTTPHeader ¶
func FromHTTPHeader(ctx context.Context, h HTTPHeaderCarrier) context.Context
FromHTTPHeader reads metainfo from a given HTTP header and sets them into the context. Note that this function does not call TransferForward inside.
func GetAllBackwardValues ¶
GetAllBackwardValues is an alias to RecvAllBackwardValues. Deprecated: for clarity, please use `RecvAllBackwardValues` instead.
func GetAllPersistentValues ¶
GetAllPersistentValues retrieves all persistent values.
func GetAllValues ¶
GetAllValues retrieves all transient values
func GetBackwardValue ¶
GetBackwardValue is an alias to `RecvBackwardValue`. Deprecated: for clarity, please use `RecvBackwardValue` instead.
func GetBackwardValueToSend ¶
GetBackwardValueToSend gets a value associated with the given key that is set by `SendBackwardValue`, `SendBackwardValues` or `SendBackwardValuesFromMap`.
func GetPersistentValue ¶
GetPersistentValue retrieves the persistent value set into the context by the given key.
func GetValueToMap ¶
GetValueToMap retrieves the value set into the context by the given key and set the value to the input map. Only use this function when you want to get a small set of values instead of GetAllValues. The logic of getting value follows GetAllValues, transient value has higher priority if key is same.
func HTTPHeaderToCGIVariable ¶
HTTPHeaderToCGIVariable performs an CGI variable conversion. For example, an HTTP header key `abc-def` will result in `ABC_DEF`.
func HasMetaInfo ¶
HasMetaInfo detects whether the given context contains metainfo.
func RangePersistentValues ¶
RangePersistentValues calls f sequentially for each persistent kv. If f returns false, range stops the iteration.
func RangeValues ¶
RangeValues calls f sequentially for each transient kv. If f returns false, range stops the iteration.
func RecvAllBackwardValues ¶
RecvAllBackwardValues is the batched version of RecvBackwardValue.
func RecvBackwardValue ¶
RecvBackwardValue gets a value associated with the given key that is set by `SetBackwardValue` or `SetBackwardValues`.
func SaveMetaInfoToMap ¶
SaveMetaInfoToMap set key-value pairs from ctx to m while filtering out transient-upstream data.
func SendBackwardValue ¶
SendBackwardValue sets a key-value pair into the context for sending to a remote endpoint. Note that the values can not be retrieved with `RecvBackwardValue` from the same context.
func SendBackwardValues ¶
SendBackwardValues is the batched version of `SendBackwardValue`.
func SendBackwardValuesFromMap ¶
SendBackwardValuesFromMap is the batched version of `SendBackwardValue`.
func SetBackwardValue ¶
SetBackwardValue sets a key value pair into the context.
func SetBackwardValues ¶
SetBackwardValues is the batched version of `SetBackwardValue`.
func SetBackwardValuesFromMap ¶
SetBackwardValuesFromMap is the batched version of `SetBackwardValue`.
func SetMetaInfoFromMap ¶
SetMetaInfoFromMap retrieves metainfo key-value pairs from the given map and sets then into the context. Only those keys with prefixes defined in this module would be used. If the context has been carrying metanifo pairs, they will be merged as a basis.
func ToHTTPHeader ¶
func ToHTTPHeader(ctx context.Context, h HTTPHeaderSetter)
ToHTTPHeader writes all metainfo into the given HTTP header. Note that this function does not call TransferForward inside. Any key or value that does not follow the HTTP specification will be discarded.
func TransferForward ¶
TransferForward converts transient values to transient-upstream values and filters out original transient-upstream values. It should be used before the context is passing from server to client.
func WithBackwardValues ¶
WithBackwardValues returns a new context that allows passing key-value pairs backward with `SetBackwardValue` from any derived context.
func WithBackwardValuesToSend ¶
WithBackwardValuesToSend returns a new context that collects key-value pairs set with `SendBackwardValue` or `SendBackwardValues` into any derived context.
func WithPersistentValue ¶
WithPersistentValue sets the value into the context by the given key. This value will be propagated to the services along the RPC call chain.
func WithPersistentValues ¶
WithPersistentValues sets the values into the context by the given keys. This value will be propagated to the services along the RPC call chain.
func WithValue ¶
WithValue sets the value into the context by the given key. This value will be propagated to the next service/endpoint through an RPC call.
Notice that it will not propagate any further beyond the next service/endpoint, Use WithPersistentValue if you want to pass a key/value pair all the way.
func WithValues ¶
WithValue sets the values into the context by the given keys. This value will be propagated to the next service/endpoint through an RPC call.
Notice that it will not propagate any further beyond the next service/endpoint, Use WithPersistentValues if you want to pass key/value pairs all the way.
Types ¶
type HTTPHeader ¶
HTTPHeader is provided to wrap an http.Header into an HTTPHeaderCarrier.
func (HTTPHeader) Set ¶
func (h HTTPHeader) Set(key, value string)
Set sets the header entries associated with key to the single element value. The key will converted into lowercase as the HTTP/2 protocol requires.
func (HTTPHeader) Visit ¶
func (h HTTPHeader) Visit(v func(k, v string))
Visit implements the HTTPHeaderCarrier interface.
type HTTPHeaderCarrier ¶
type HTTPHeaderCarrier interface {
Visit(func(k, v string))
}
HTTPHeaderCarrier accepts a visitor to access all key value pairs in an HTTP header.
type HTTPHeaderSetter ¶
type HTTPHeaderSetter interface {
Set(key, value string)
}
HTTPHeaderSetter sets a key with a value into a HTTP header.