Documentation
¶
Overview ¶
Package ecinterface defines the interfaces of edgecontext package used in Baseplate.go.
The actual edgecontext implementation is provided in a separated library, but it implements the interfaces defined in this package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrGetBeforeSet = errors.New("ecinterface: Get called before Set is called")
ErrGetBeforeSet is the error returned when Get is called before Set.
var Logger log.Wrapper
Logger is used by Get when it's called before Set is called.
Functions ¶
Types ¶
type Factory ¶
type Factory func(args FactoryArgs) (Interface, error)
Factory is the callback used by baseplate.New to create the implementation.
type FactoryArgs ¶
FactoryArgs defines the args used in Factory.
type Interface ¶
type Interface interface { // HeaderToContext parses the edge context from header, // then inject the object into context. HeaderToContext(ctx context.Context, header string) (context.Context, error) // ContextToHeader extracts edge context object from context, // then serializes it into header. // // It shall return ("", false) when there's no edge context attached to ctx. ContextToHeader(ctx context.Context) (header string, ok bool) }
Interface defines the interface edgecontext implementation must implements.
The string "header" does not necessarily need to be ASCII/UTF-8 string. For thrift those headers will be used as-is, for HTTP those headers will always be wrapped with additional base64 encoding.
func Get ¶
func Get() Interface
Get returns the previously Set global edge context implementation.
It's guaranteed to return a non-nil implementation. If it's called before any Set is called, it logs the event (via Logger), then returns an implementation that does nothing:
- Its HeaderToContext always return the context intact with ErrGetBeforeSet.
- Its ContextToHeader always return ("", false).