label

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB implements the Store interface using a postgres database.

func NewDB

func NewDB(ctx context.Context, db *sql.DB) (*DB, error)

NewDB will Set a DB backend from a sql.DB. An error will be returned if statements fail to prepare.

func (*DB) FindAllByService

func (db *DB) FindAllByService(ctx context.Context, serviceID string) ([]Label, error)

FindAllByService finds all labels for a particular service. It returns all key-value pairs.

func (*DB) Search

func (db *DB) Search(ctx context.Context, opts *SearchOptions) ([]Label, error)

func (*DB) SetTx

func (db *DB) SetTx(ctx context.Context, tx *sql.Tx, label *Label) error

SetTx will set a label for the service. It can be used to set the key-value pair for the label, delete a label or update the value given the label's key.

func (*DB) UniqueKeys

func (db *DB) UniqueKeys(ctx context.Context) ([]string, error)

func (*DB) UniqueKeysTx

func (db *DB) UniqueKeysTx(ctx context.Context, tx *sql.Tx) ([]string, error)

type Label

type Label struct {
	Target assignment.Target
	Key    string `json:"key"`
	Value  string `json:"value"`
}

A Label is a key-value pair assigned to a target.

func (Label) Normalize

func (l Label) Normalize() (*Label, error)

Normalize will validate and normalize the label, returning a copy.

type SearchCursor

type SearchCursor struct {
	Key        string                `json:"k,omitempty"`
	TargetID   string                `json:"t,omitempty"`
	TargetType assignment.TargetType `json:"y,omitempty"`
}

SearchCursor is used to indicate a position in a paginated list.

type SearchOptions

type SearchOptions struct {
	Search string       `json:"s,omitempty"`
	After  SearchCursor `json:"a,omitempty"`

	// Omit specifies a list of key names to exclude from the results.
	Omit []string `json:"o,omitempty"`

	Limit int `json:"-"`

	UniqueKeys bool `json:"u,omitempty"`
}

SearchOptions allow filtering and paginating the list of rotations.

type Store

type Store interface {
	SetTx(ctx context.Context, tx *sql.Tx, label *Label) error
	FindAllByService(ctx context.Context, serviceID string) ([]Label, error)
	UniqueKeysTx(ctx context.Context, tx *sql.Tx) ([]string, error)
	UniqueKeys(ctx context.Context) ([]string, error)
	Search(ctx context.Context, opts *SearchOptions) ([]Label, error)
}

Store allows the lookup and management of Labels.

Jump to

Keyboard shortcuts

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