backend

package
v0.0.0-...-1643519 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package backend implements configuration client backend interface and associated data types.

The backend package implements a generalized implementation-oriented interface to configuration services that can be layered. Various backend implementations are best defined out of this package.

All non-user-facing operations of cfgclient will operate on backend types.

Index

Constants

View Source
const (
	// GetAllProject indicates that project configus should be retrieved.
	GetAllProject = GetAllTarget("Project")
	// GetAllRef indicates that ref configs should be retrieved.
	GetAllRef = GetAllTarget("Ref")
)

Variables

This section is empty.

Functions

func WithBackend

func WithBackend(c context.Context, b B) context.Context

WithBackend returns a derivative Context with the supplied Backend installed.

func WithFactory

func WithFactory(c context.Context, f Factory) context.Context

WithFactory returns a derivative Context with the supplied BackendFactory installed.

Types

type Authority

type Authority int

Authority is the authority that is requesting configurations. It can be installed via WithAuthority.

Authority marshals/unmarshals to/from a compact JSON representation. This is used by the caching layer.

const (
	// AsAnonymous requests config data as an anonymous user.
	//
	// Corresponds to auth.NoAuth.
	AsAnonymous Authority = iota

	// AsService requests config data as the currently-running service.
	//
	// Corresponds to auth.AsSelf.
	AsService

	// AsUser requests config data as the currently logged-in user.
	//
	// Corresponds to auth.AsUser.
	AsUser
)

func (Authority) MarshalJSON

func (a Authority) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json.Marshaler.

We use a shorthand notation so that we don't waste space in JSON.

func (Authority) String

func (i Authority) String() string

func (*Authority) UnmarshalJSON

func (a *Authority) UnmarshalJSON(d []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler.

type B

type B interface {
	// ServiceURL returns the service URL.
	ServiceURL(context.Context) url.URL

	// Get retrieves a single configuration.
	Get(c context.Context, configSet config.Set, path string, p Params) (*config.Config, error)

	// GetAll retrieves all configurations of a given type.
	GetAll(c context.Context, t GetAllTarget, path string, p Params) ([]*config.Config, error)

	// GetConfigInterface returns the raw configuration interface of the backend.
	GetConfigInterface(c context.Context, a Authority) config.Interface
}

B is a configuration backend interface.

func Get

func Get(c context.Context) B

Get returns the Backend that is installed into the Context.

If no Backend is installed in the Context, Get will panic.

type Factory

type Factory func(context.Context) B

Factory is a function that generates a B given a Context.

type GetAllTarget

type GetAllTarget string

GetAllTarget is the type of configuration to retrieve with GetAll.

GetAllTarget marshals/unmarshals to/from a compact JSON representation. This is used by the caching layer.

func (GetAllTarget) MarshalJSON

func (gat GetAllTarget) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*GetAllTarget) UnmarshalJSON

func (gat *GetAllTarget) UnmarshalJSON(d []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Params

type Params struct {
	// Authority is the authority to use in the request.
	Authority Authority
	// Content, if true, indicates that config content should also be fetched.
	// Otherwise, only the content hash needs to be returned.
	Content bool

	// FormatSpec, if non-empty, qualifies the format of the Content.
	FormatSpec config.FormatSpec
}

Params are parameters supplied to Backend methods. They are generated by the main interface user-facing methods (config.go)

Directories

Path Synopsis
Package caching implements a config.Interface that uses a caching layer to store its configuration values.
Package caching implements a config.Interface that uses a caching layer to store its configuration values.
Package client implements a config client backend for a configuration client.
Package client implements a config client backend for a configuration client.
Package erroring implements config.Backend that simply returns an error.
Package erroring implements config.Backend that simply returns an error.
Package format implements a config client Backend that performs formatting on items.
Package format implements a config client Backend that performs formatting on items.

Jump to

Keyboard shortcuts

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