Documentation ¶
Index ¶
- Constants
- func Connect(config configuration.Configuration) (*gorm.DB, error)
- func LogStorageStats(ctx context.Context, store Store, interval time.Duration) error
- func PostgresConfigString(config configuration.Configuration) string
- type DBStore
- func (s *DBStore) CreateRequest(r *Request) error
- func (s *DBStore) CreateStatistics(o *Statistics) error
- func (s *DBStore) DeleteRequest(r *Request) error
- func (s *DBStore) GetRequests(ns string) (result []Request, err error)
- func (s *DBStore) GetRequestsCount(ns string) (result int, err error)
- func (s *DBStore) GetStatisticsUser(ns string) (o *Statistics, notFound bool, err error)
- func (s *DBStore) GetUsers() (result []string, err error)
- func (s *DBStore) IncrementRequestRetry(r *Request) (errs []error)
- func (s *DBStore) LogStats()
- func (s *DBStore) UpdateStatistics(o *Statistics) error
- type Mock
- func (s *Mock) CreateRequest(r *Request) error
- func (s *Mock) CreateStatistics(o *Statistics) error
- func (s *Mock) DeleteRequest(r *Request) error
- func (s *Mock) GetRequests(ns string) (result []Request, err error)
- func (s *Mock) GetRequestsCount(ns string) (result int, err error)
- func (s *Mock) GetStatisticsUser(ns string) (o *Statistics, notFound bool, err error)
- func (s *Mock) GetUsers() (result []string, err error)
- func (s *Mock) IncrementRequestRetry(r *Request) (errs []error)
- func (s *Mock) LogStats()
- func (s *Mock) UpdateStatistics(o *Statistics) error
- type Request
- type Statistics
- type Store
Constants ¶
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 ¶
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 ¶
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 ¶
DeleteRequest deletes a request from the database.
func (*DBStore) GetRequests ¶
GetRequests gets one or more requests from the database given a namespace as input.
func (*DBStore) GetRequestsCount ¶
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) IncrementRequestRetry ¶
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 ¶
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 ¶
DeleteRequest deletes a request from the database.
func (*Mock) GetRequests ¶
GetRequests gets one or more requests from the database given a namespace as input.
func (*Mock) GetRequestsCount ¶
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) IncrementRequestRetry ¶
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 ¶
NewRequest creates a new request for a namespace.
func (Request) GetHTTPRequest ¶
GetHTTPRequest wraps an *http.Request from this request.
func (Request) GetHeaders ¶
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.
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 ¶
NewDBStorage creates an instance of database client.