backend

package
v0.0.0-...-6f34b33 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package backend provides a standard way to construct a coordinate interface based on command-line flags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// Implementation holds the name of the implementation; for
	// instance, "memory".
	Implementation string

	// Address holds some backend-specific address, such as a
	// database connect string.
	Address string
}

Backend describes user-visible parameters to store coordinate data. This implements the flag.Value interface, and so a typical use is

func main() {
    backend := backend.Backend{"memory", ""}
    flag.Var(&backend, "backend", "impl:address of coordinate storage")
    flag.Parse()
    coordinate := backend.Coordinate()
}

func (*Backend) Coordinate

func (b *Backend) Coordinate() (coordinate.Coordinate, error)

Coordinate creates a new coordinate interface. This generally should be only called once. If the backend has in-process state, such as a database connection pool or an in-memory story, calling this multiple times will create multiple copies of that state. In particular, if b.Implementation is "memory", multiple calls to this will create multiple independent coordinate "worlds".

If b.Implementation does not match a known implementation, returns an error. It is assumed that Set() will validate at least the implementation. The choice of implementation can also produce errors (invalid connection string, etc.)

func (*Backend) Set

func (b *Backend) Set(param string) (err error)

Set parses a string into an existing backend description. The string should be of the form "implementation:address", where address can be any string. Set checks to see if the provided implementation is any of the known implementations, and returns an appropriate error if not.

This is part of the flag.Value interface. If Set returns a nil error then Coordinate() will return successfully. Note that neither function attempts to validate the b.Address part of the string or attempts to actually make a connection.

func (*Backend) String

func (b *Backend) String() string

String renders a backend description as a string.

Jump to

Keyboard shortcuts

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