ecinterface

package
v0.9.17 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: BSD-3-Clause Imports: 8 Imported by: 1

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

View Source
var ErrGetBeforeSet = errors.New("ecinterface: Get called before Set is called")

ErrGetBeforeSet is the error returned when Get is called before Set.

View Source
var Logger log.Wrapper

Logger is used by Get when it's called before Set is called.

Functions

func Set

func Set(impl Interface)

Set sets the global edge context implementation.

Types

type Factory

type Factory func(args FactoryArgs) (Interface, error)

Factory is the callback used by baseplate.New to create the implementation.

type FactoryArgs

type FactoryArgs struct {
	Store *secrets.Store
}

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).

func Mock

func Mock() Interface

Mock creates a mocked Interface.

Jump to

Keyboard shortcuts

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