Documentation

Overview

    Package pila represents the Go library that handles the Pila, databases and stacks.

    Index

    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

      func NewDatabase(name string) *Database

        NewDatabase creates a new Database given a name, without any link to the piladb instance.

        func (*Database) AddStack

        func (db *Database) AddStack(stack *Stack) error

          AddStack adds a given Stack to the Database, returning an error if any was found.

          func (*Database) CreateStack

          func (db *Database) CreateStack(name string, t time.Time) fmt.Stringer

            CreateStack creates a new Stack, given a name and a creation date, which is associated to the Database.

            func (*Database) CreateStackWithBase

            func (db *Database) CreateStackWithBase(name string, t time.Time, base stack.Stacker) fmt.Stringer

              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

              func (db *Database) RemoveStack(id fmt.Stringer) bool

                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

                func (db *Database) StacksKV() 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.

                            func (*Element) Decode

                            func (element *Element) Decode(r io.Reader) error

                              Decode decodes json data into an Element.

                              func (Element) ToJSON

                              func (element Element) ToJSON() ([]byte, error)

                                ToJSON converts an Element into JSON.

                                type Pila

                                type Pila struct {
                                	Databases map[fmt.Stringer]*Database
                                }

                                  Pila contains a reference to all the existing Databases, i.e. the currently running piladb instance.

                                  func NewPila

                                  func NewPila() *Pila

                                    NewPila return a blank piladb instance

                                    func (*Pila) AddDatabase

                                    func (p *Pila) AddDatabase(db *Database) error

                                      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

                                      func (p *Pila) CreateDatabase(name string) fmt.Stringer

                                        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

                                        func (p *Pila) Database(id fmt.Stringer) (*Database, bool)

                                          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

                                          func (p *Pila) RemoveDatabase(id fmt.Stringer) bool

                                            RemoveDatabase deletes a Database given an ID from the Pila and returns true if it succeeded.

                                            func (*Pila) Status

                                            func (p *Pila) Status() Status

                                              Status returns the status of the Pila.

                                              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

                                                func NewStack(name string, t time.Time) *Stack

                                                  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

                                                  func NewStackWithBase(name string, t time.Time, base stack.Stacker) *Stack

                                                    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) Flush

                                                    func (s *Stack) Flush()

                                                      Flush flushes the content of the Stack.

                                                      func (*Stack) Peek

                                                      func (s *Stack) Peek() interface{}

                                                        Peek returns the element on top of the Stack.

                                                        func (*Stack) Pop

                                                        func (s *Stack) Pop() (interface{}, bool)

                                                          Pop removes and returns the element on top of the Stack. If the Stack was empty, it returns false.

                                                          func (*Stack) Push

                                                          func (s *Stack) Push(element interface{})

                                                            Push an element on top of the Stack.

                                                            func (*Stack) Read

                                                            func (s *Stack) Read(t time.Time)

                                                              Read takes a date and updates ReadAt field of the Stack.

                                                              func (*Stack) SetDatabase

                                                              func (s *Stack) SetDatabase(db *Database)

                                                                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) Size

                                                                  func (s *Stack) Size() int

                                                                    Size returns the size of the Stack.

                                                                    func (*Stack) SizeToJSON

                                                                    func (s *Stack) SizeToJSON() []byte

                                                                      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) UUID

                                                                        func (s *Stack) UUID() fmt.Stringer

                                                                          UUID returns the unique Stack ID providing thread safety.

                                                                          func (*Stack) Update

                                                                          func (s *Stack) Update(t time.Time)

                                                                            Update takes a date and updates UpdateAt and ReadAt fields of the Stack.

                                                                            type StackStatus

                                                                            type StackStatus struct {
                                                                            	ID        string      `json:"id"`
                                                                            	Name      string      `json:"name"`
                                                                            	Peek      interface{} `json:"peek"`
                                                                            	Size      int         `json:"size"`
                                                                            	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

                                                                                type StackStatuser interface {
                                                                                	ToJSON() ([]byte, error)
                                                                                }

                                                                                  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.

                                                                                    func (StacksKV) ToJSON

                                                                                    func (stacksKV StacksKV) ToJSON() ([]byte, error)

                                                                                      ToJSON converts a StacksKV into JSON.

                                                                                      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.

                                                                                                type Status

                                                                                                type Status struct {
                                                                                                	NumberDatabases int              `json:"number_of_databases"`
                                                                                                	Databases       []DatabaseStatus `json:"databases"`
                                                                                                }

                                                                                                  Status contains the status of the Pila instance.

                                                                                                  func (Status) ToJSON

                                                                                                  func (pilaStatus Status) ToJSON() []byte

                                                                                                    ToJSON converts a Status into JSON.