core

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RequestGET defines a GET HTTP request method.
	RequestGET = "GET"
)

Variables

View Source
var (
	BadgerAlertsNamespace   = []byte("alerts")
	BadgerMonitorsNamespace = []byte("monitors")
)

Badger namespaces

Functions

func Request

func Request(url, method string, payload []byte) ([]byte, error)

Request implements a generic HTTP request handler. It will invoke a request of type method to the given url with an optional payload. The raw response body and any error will be returned.

Types

type BadgerDB

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

BadgerDB is a wrapper around a BadgerDB backend database that implements the DB interface.

func (*BadgerDB) Close

func (bdb *BadgerDB) Close() error

Close implements the DB interface. It closes the connection to the underlying BadgerDB database as well as invoking the context's cancel function.

func (*BadgerDB) Get

func (bdb *BadgerDB) Get(namespace, key []byte) (value []byte, err error)

Get implements the DB interface. It attempts to get a value for a given key and namespace. If the key does not exist in the provided namespace, an error is returned, otherwise the retrieved value.

func (*BadgerDB) Has

func (bdb *BadgerDB) Has(namespace, key []byte) (ok bool, err error)

Has implements the DB interface. It returns a boolean reflecting if the database has a given key for a namespace or not. An error is only returned if an error to Get would be returned that is not of type badger.ErrKeyNotFound.

func (*BadgerDB) Set

func (bdb *BadgerDB) Set(namespace, key, value []byte) error

Set implements the DB interface. It attempts to store a value for a given key and namespace. If the key/value pair cannot be saved, an error is returned.

func (*BadgerDB) SetWithTTL

func (bdb *BadgerDB) SetWithTTL(namespace, key, value []byte, ttl time.Duration) error

SetWithTTL implements the DB interface. It attempts to store a value for a given key, namespace and TTL duration. If the key/value pair cannot be saved, an error is returned.

type ClientManager

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

ClientManager implements a simple round-robin load balancing client manager.

func NewClientManager

func NewClientManager(clients []string) *ClientManager

NewClientManager returns a reference to a new initialized ClientManager with a given list of clients.

func (*ClientManager) Next

func (cm *ClientManager) Next() string

Next returns the next client to be used from the client manager. Each client is round-robin load balanced.

type DB

type DB interface {
	Get(namespace, key []byte) (value []byte, err error)
	Set(namespace, key, value []byte) error
	Has(namespace, key []byte) (bool, error)
	SetWithTTL(namespace, key, value []byte, ttl time.Duration) error
	Close() error
}

DB defines an embedded key/value store database interface.

func NewBadgerDB

func NewBadgerDB(cfg config.Config, logger Logger) (DB, error)

NewBadgerDB returns a new initialized BadgerDB database implementing the DB interface. If the database cannot be initialized, an error will be returned.

type Logger

type Logger struct {
	log.FieldLogger
}

Logger is a simple wrapper around a Logrus logger.

func CreateBaseLogger

func CreateBaseLogger(logOut string, debug bool) (Logger, error)

CreateBaseLogger creates a base logger for which other components and modules can extend upon, inheriting the base configuration and settings of a core logger. An error is returned if a non-empty log file path is given that cannot be created.

func NewLogger

func NewLogger(out io.Writer, debug bool) Logger

NewLogger returns a new initialized logger with the level, formatter, and output set.

func (Logger) With

func (logger Logger) With(key, value string) Logger

With returns a new logger with the given key/value field mapping.

Jump to

Keyboard shortcuts

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