Documentation ¶
Overview ¶
Package pila represents the Go library that handles the Pila, databases and stacks.
Index ¶
- type Database
- func (db *Database) AddStack(stack *Stack) error
- func (db *Database) CreateStack(name string, t time.Time) fmt.Stringer
- func (db *Database) CreateStackWithBase(name string, t time.Time, base stack.Stacker) fmt.Stringer
- func (db *Database) RemoveStack(id fmt.Stringer) bool
- func (db *Database) StacksKV() StacksKV
- func (db *Database) StacksStatus() StacksStatus
- func (db *Database) Status() DatabaseStatus
- type DatabaseStatus
- type Element
- type Pila
- type Stack
- func (s *Stack) Base(element interface{}) error
- func (s *Stack) Block()
- func (s *Stack) Blocked() bool
- func (s *Stack) Empty() bool
- func (s *Stack) Flush() error
- func (s *Stack) Peek() interface{}
- func (s *Stack) Pop() (interface{}, error)
- func (s *Stack) Push(element interface{}) error
- func (s *Stack) Read(t time.Time)
- func (s *Stack) Rotate() error
- func (s *Stack) SetDatabase(db *Database)
- func (s *Stack) SetID()
- func (s *Stack) Size() int
- func (s *Stack) SizeToJSON() []byte
- func (s *Stack) Status() StackStatus
- func (s *Stack) Sweep() (interface{}, error)
- func (s *Stack) SweepPush(element interface{}) (interface{}, error)
- func (s *Stack) UUID() fmt.Stringer
- func (s *Stack) Unblock()
- func (s *Stack) Update(t time.Time)
- type StackStatus
- type StackStatuser
- type StacksKV
- type StacksStatus
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database struct { // ID is a unique identifier of the database ID fmt.Stringer // Name of the database Name string // Pointer to the current piladb instance Pila *Pila // Stacks associated to Database mapped by their ID Stacks map[fmt.Stringer]*Stack // contains filtered or unexported fields }
Database represents a piladb database.
func NewDatabase ¶
NewDatabase creates a new Database given a name, without any link to the piladb instance.
func (*Database) AddStack ¶
AddStack adds a given Stack to the Database, returning an error if any was found.
func (*Database) CreateStack ¶
CreateStack creates a new Stack, given a name and a creation date, which is associated to the Database.
func (*Database) CreateStackWithBase ¶ added in v0.1.1
CreateStackWithBase creates a new Stack, given a name, a creation date, and a stack.Stacker base implementation, which is associated to the Database.
func (*Database) RemoveStack ¶
RemoveStack removes a Stack from the Database given an id, returning true if it succeeded. It will return false if the Stack wasn't added to the Database.
func (*Database) StacksKV ¶
StacksKV returns the status of the Stacks of Database in a key-value format.
func (*Database) StacksStatus ¶
func (db *Database) StacksStatus() StacksStatus
StacksStatus returns the status of the Stacks of Database.
func (*Database) Status ¶
func (db *Database) Status() DatabaseStatus
Status returns the status of the Database.
type DatabaseStatus ¶
type DatabaseStatus struct { ID string `json:"id"` Name string `json:"name"` NumberStacks int `json:"number_of_stacks"` Stacks []string `json:"stacks,omitempty"` }
DatabaseStatus represents the status of a Database.
func (DatabaseStatus) ToJSON ¶
func (databaseStatus DatabaseStatus) ToJSON() []byte
ToJSON converts a DatabaseStatus into JSON.
type Element ¶
type Element struct {
Value interface{} `json:"element"`
}
Element represents the payload of a Stack element.
type Pila ¶
Pila contains a reference to all the existing Databases, i.e. the currently running piladb instance.
func (*Pila) AddDatabase ¶
AddDatabase adds a given Database to the Pila. It returns and error if the Database already had an assigned Pila, or if the Pila already contained the Database.
func (*Pila) CreateDatabase ¶
CreateDatabase creates a database given a name, and build the relation between such database and the Pila. It return the ID of the database. If a Database called `name` already exists, it will be restarted. So please consider using AddDatabase in case of possible conflicts.
func (*Pila) Database ¶
Database determines if a Database given by an ID is part of the Pila, returning a pointer to the Database and a boolean flag.
func (*Pila) RemoveDatabase ¶
RemoveDatabase deletes a Database given an ID from the Pila and returns true if it succeeded.
type Stack ¶
type Stack struct { // ID is a unique identifier of the Stack // Note: Do not use this field to read the ID, // as this method is not thread-safe. See UUID() // instead. ID fmt.Stringer // Name of the Stack Name string // Database associated to the Stack Database *Database // CreatedAt represents the date when the Stack was created CreatedAt time.Time // UpdatedAt represents the date when the Stack was updated for the last time. // This date must be updated when a Stack is created, and when receives a PUSH, // POP, or FLUSH operation. // Note that unlike CreatedAt, UpdatedAt is not triggered automatically // when one of these events happens, but it needs to be set by hand. UpdatedAt time.Time // ReadAt represents the date when the Stack was read for the last time. // This date must be updated when a Stack is created, accessed, and when it // receives a PUSH, POP, or FLUSH operation. // Note that unlike CreatedAt, ReadAt is not triggered automatically // when one of these events happens, but it needs to be set by hand. ReadAt time.Time // IDMu provides a mutex to handle concurrent reads and // writes on the Stack ID. IDMu sync.RWMutex // contains filtered or unexported fields }
Stack represents a stack entity in piladb.
func NewStack ¶
NewStack creates a new Stack given a name and a creation date, without an association to any Database. It uses the default ./pkg/stack implementation as a base Stack.
func NewStackWithBase ¶ added in v0.1.1
NewStackWithBase creates a new Stack given a name, a creation date, and a stack.Stacker base implementation, without an association to any Database.
func (*Stack) Base ¶
Base bases the Stack on an element, so this becomes the bottommost one of the Stack.
func (*Stack) Peek ¶
func (s *Stack) Peek() interface{}
Peek returns the element on top of the Stack.
func (*Stack) Pop ¶
Pop removes and returns the element on top of the Stack. If the Stack was empty, it returns false.
func (*Stack) Rotate ¶
Rotate moves the bottommost element of the Stack to the top. If the Stack is empty or blocked, it returns an error.
func (*Stack) SetDatabase ¶
SetDatabase links the Stack with a given Database and recalculates its ID.
func (*Stack) SetID ¶
func (s *Stack) SetID()
SetID recalculates the id of the Stack based on its Database name and its own name.
func (*Stack) SizeToJSON ¶
SizeToJSON returns the size of the Stack encoded as json.
func (*Stack) Status ¶
func (s *Stack) Status() StackStatus
Status returns the status of the Stack in json format.
func (*Stack) Sweep ¶
Sweep removes and returns the bottommost element of the Stack. If the Stack is empty or blocked, it returns an error.
func (*Stack) SweepPush ¶
SweepPush removes and returns the bottommost element of the Stack, and pushes an element on top of it, as an atomic operation. If the Stack is empty or blocked, it returns an error.
type StackStatus ¶
type StackStatus struct { ID string `json:"id"` Name string `json:"name"` Peek interface{} `json:"peek"` Size int `json:"size"` Blocked bool `json:"blocked"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` ReadAt time.Time `json:"read_at"` }
StackStatus represents the status of a Stack.
func (StackStatus) ToJSON ¶
func (stackStatus StackStatus) ToJSON() ([]byte, error)
ToJSON converts a StackStatus into JSON.
type StackStatuser ¶
StackStatuser represents an interface for types representing the status of stacks or stacks in different formats.
type StacksKV ¶
type StacksKV struct {
Stacks map[string]interface{} `json:"stacks"`
}
StacksKV represents a list of status by a key-value list composed by name and peek of the Stack.
type StacksStatus ¶
type StacksStatus struct {
Stacks []StackStatus `json:"stacks"`
}
StacksStatus represents the status of a list of Stacks.
func (StacksStatus) Len ¶
func (stacksStatus StacksStatus) Len() int
Len return the length of the list of Stacks.
func (StacksStatus) Less ¶
func (stacksStatus StacksStatus) Less(i, j int) bool
Less determines whether a StackStatus on the list is less than other.
func (StacksStatus) Swap ¶
func (stacksStatus StacksStatus) Swap(i, j int)
Swap swaps positions between two StackStatus.
func (StacksStatus) ToJSON ¶
func (stacksStatus StacksStatus) ToJSON() ([]byte, error)
ToJSON converts a StacksStatus into JSON.