storage

package
v0.0.0-...-9ac85d6 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrorFailedDelete is the error message on failing to delete a request.
	ErrorFailedDelete = "failed to delete request for %s (%s): %s"
)

Variables

This section is empty.

Functions

func Connect

func Connect(config configuration.Configuration) (*gorm.DB, error)

Connect sets up a database connection by using configuration given as input.

func LogStorageStats

func LogStorageStats(ctx context.Context, store Store, interval time.Duration) error

LogStorageStats enables logging of stogare statistics.

func PostgresConfigString

func PostgresConfigString(config configuration.Configuration) string

PostgresConfigString returns a ready to use string for usage in sql.Open().

Types

type DBStore

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

DBStore describes a database client.

func (*DBStore) CreateRequest

func (s *DBStore) CreateRequest(r *Request) error

CreateRequest creates an entry of request in the database.

func (*DBStore) CreateStatistics

func (s *DBStore) CreateStatistics(o *Statistics) error

CreateStatistics creates an entry of Statistics in the database.

func (*DBStore) DeleteRequest

func (s *DBStore) DeleteRequest(r *Request) error

DeleteRequest deletes a request from the database.

func (*DBStore) GetRequests

func (s *DBStore) GetRequests(ns string) (result []Request, err error)

GetRequests gets one or more requests from the database given a namespace as input.

func (*DBStore) GetRequestsCount

func (s *DBStore) GetRequestsCount(ns string) (result int, err error)

GetRequestsCount gets requests count given a namespace.

func (*DBStore) GetStatisticsUser

func (s *DBStore) GetStatisticsUser(ns string) (o *Statistics, notFound bool, err error)

GetStatisticsUser gets Statistics of a namespace from the database.

func (*DBStore) GetUsers

func (s *DBStore) GetUsers() (result []string, err error)

GetUsers gets namespaces from the database.

func (*DBStore) IncrementRequestRetry

func (s *DBStore) IncrementRequestRetry(r *Request) (errs []error)

IncrementRequestRetry increases retries for a given request in the database.

func (*DBStore) LogStats

func (s *DBStore) LogStats()

LogStats logs number of cached number of cached requests and statistics entries count.

func (*DBStore) UpdateStatistics

func (s *DBStore) UpdateStatistics(o *Statistics) error

UpdateStatistics updates Statistics in the database.

type Mock

type Mock struct {
}

Mock is a mock implementation of Store struct. This implementation is meant to be used for testing

func (*Mock) CreateRequest

func (s *Mock) CreateRequest(r *Request) error

CreateRequest creates an entry of request in the database.

func (*Mock) CreateStatistics

func (s *Mock) CreateStatistics(o *Statistics) error

CreateStatistics creates an entry of Statistics in the database.

func (*Mock) DeleteRequest

func (s *Mock) DeleteRequest(r *Request) error

DeleteRequest deletes a request from the database.

func (*Mock) GetRequests

func (s *Mock) GetRequests(ns string) (result []Request, err error)

GetRequests gets one or more requests from the database given a namespace as input.

func (*Mock) GetRequestsCount

func (s *Mock) GetRequestsCount(ns string) (result int, err error)

GetRequestsCount gets requests count given a namespace.

func (*Mock) GetStatisticsUser

func (s *Mock) GetStatisticsUser(ns string) (o *Statistics, notFound bool, err error)

GetStatisticsUser gets Statistics of a namespace from the database.

func (*Mock) GetUsers

func (s *Mock) GetUsers() (result []string, err error)

GetUsers gets namespaces from the database.

func (*Mock) IncrementRequestRetry

func (s *Mock) IncrementRequestRetry(r *Request) (errs []error)

IncrementRequestRetry increases retries for a given request in the database.

func (*Mock) LogStats

func (s *Mock) LogStats()

LogStats logs number of cached number of cached requests and statistics entries count.

func (*Mock) UpdateStatistics

func (s *Mock) UpdateStatistics(o *Statistics) error

UpdateStatistics updates Statistics in the database.

type Request

type Request struct {
	ID        uuid.UUID `sql:"type:uuid" gorm:"primary_key"` // This is the ID PK field
	Method    string
	Headers   []byte
	Payload   []byte
	Host      string
	Scheme    string
	Path      string
	Namespace string
	Retries   int
}

Request describes an HTTP request.

func NewRequest

func NewRequest(r *http.Request, ns string, body []byte) (*Request, error)

NewRequest creates a new request for a namespace.

func (Request) GetHTTPRequest

func (m Request) GetHTTPRequest() (r *http.Request, err error)

GetHTTPRequest wraps an *http.Request from this request.

func (Request) GetHeaders

func (m Request) GetHeaders() (result map[string][]string, err error)

GetHeaders gets headers of the this request.

func (Request) GetPayloadReader

func (m Request) GetPayloadReader() io.ReadCloser

GetPayloadReader returns an io reader for the request payload.

func (Request) TableName

func (m Request) TableName() string

TableName for current request.

type Statistics

type Statistics struct {
	Namespace           string `gorm:"primary_key"` // This is the ID PK field
	LastAccessed        int64
	LastBufferedRequest int64
}

Statistics consists of namespace, last time time was accessed and last buffered request to that namespace.

func NewStatistics

func NewStatistics(ns string, la int64, lbr int64) *Statistics

NewStatistics returns an instance of statistics on giving namespace, last accessed time and last buffered request as an input.

func (Statistics) String

func (m Statistics) String() string

func (Statistics) TableName

func (m Statistics) TableName() string

TableName returns table name for the given statistics.

type Store

type Store interface {
	CreateRequest(r *Request) error
	GetRequests(ns string) (result []Request, err error)
	IncrementRequestRetry(r *Request) (errs []error)
	GetUsers() (result []string, err error)
	GetRequestsCount(ns string) (result int, err error)
	DeleteRequest(r *Request) error

	CreateStatistics(o *Statistics) error
	UpdateStatistics(o *Statistics) error
	GetStatisticsUser(ns string) (o *Statistics, notFound bool, err error)

	LogStats()
}

Store includes all methods required to interact with the database

func NewDBStorage

func NewDBStorage(db *gorm.DB) Store

NewDBStorage creates an instance of database client.

Jump to

Keyboard shortcuts

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