database

package
v0.0.0-...-93b8736 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: 0BSD Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	Version   int      `json:"version"`
	CachePass string   `json:"cachepass"`
	Entries   []*Entry `json:"entries"`
}

DB represents an in-memory database of password records.

func FromJSON

func FromJSON(input []byte) (*DB, error)

FromJSON initializes a database instance from JSON.

func New

func New(cachepass string) *DB

New initializes a new database instance.

func (*DB) Active

func (db *DB) Active() EntryList

Active returns a list containing all the database's active entries.

func (*DB) Add

func (db *DB) Add(entry *Entry) int

Add inserts a new entry into the database. Returns the new entry's ID.

func (*DB) All

func (db *DB) All() EntryList

All returns a list containing all the database's entries.

func (*DB) Count

func (db *DB) Count() int

Count returns the number of active entries in the database.

func (*DB) Import

func (db *DB) Import(data []byte) (int, error)

Import adds entries to the database from JSON. The entries must have been exported using an EntryList's Export() method. Returns the number of new entrie.

func (*DB) Inactive

func (db *DB) Inactive() EntryList

Inactive returns a list containing all the database's inactive entries.

func (*DB) PurgeInactive

func (db *DB) PurgeInactive()

Purge clears inactive entries from the database.

func (*DB) SetActive

func (db *DB) SetActive(id int)

SetActive sets an entry's active status to true.

func (*DB) SetInactive

func (db *DB) SetInactive(id int)

SetInactive sets an entry's active status to false.

func (*DB) TagMap

func (db *DB) TagMap() map[string]EntryList

TagMap returns a map of tags to entry-lists.

func (*DB) ToJSON

func (db *DB) ToJSON() ([]byte, error)

ToJSON serializes a database instance to JSON.

type Entry

type Entry struct {
	Id        int      `json:"id"`
	Active    bool     `json:"active"`
	Title     string   `json:"title"`
	Url       string   `json:"url"`
	Username  string   `json:"username"`
	Passwords []string `json:"passwords"`
	Email     string   `json:"email"`
	Tags      []string `json:"tags"`
	Notes     string   `json:"notes"`
}

An Entry object represents a single database record.

func NewEntry

func NewEntry() *Entry

NewEntry initializes a new Entry object.

func (*Entry) GetPassword

func (entry *Entry) GetPassword() string

GetPassword returns the newest password from the passwords list.

func (*Entry) SetPassword

func (entry *Entry) SetPassword(password string)

SetPassword appends a new password to the passsword list.

type EntryList

type EntryList []*Entry

An EntryList is a slice of Entry pointers.

func (EntryList) Export

func (list EntryList) Export() (string, error)

Export exports the EntryList as formatted JSON.

func (EntryList) FilterActive

func (list EntryList) FilterActive() EntryList

FilterActive returns a new EntryList containing active entries.

func (EntryList) FilterByAll

func (list EntryList) FilterByAll(queries ...string) EntryList

FilterByAll returns a new EntryList containing entries which match *all* of the specified query strings, where each query string is a case-insensitive substring of the entry title. If a single query string is supplied, it will first be checked to see if it matches a valid entry ID.

func (EntryList) FilterByAny

func (list EntryList) FilterByAny(queries ...string) EntryList

FilterByAny returns a new EntryList containing entries which match *any* of the specified query strings. A query string can be an entry ID or a case-insensitive substring of an entry title.

func (EntryList) FilterByID

func (list EntryList) FilterByID(ids ...int) EntryList

FilterByID returns a new EntryList containing entries with matching IDs.

func (EntryList) FilterByTag

func (list EntryList) FilterByTag(tag string) EntryList

FilterByTag returns a new EntryList containing entries which match the specified tag. Matches are case-insensitive.

func (EntryList) FilterInactive

func (list EntryList) FilterInactive() EntryList

FilterInactive returns a new EntryList containing inactive entries.

type ExportEntry

type ExportEntry struct {
	Title     string   `json:"title"`
	Url       string   `json:"url"`
	Username  string   `json:"username"`
	Passwords []string `json:"passwords"`
	Email     string   `json:"email"`
	Tags      []string `json:"tags"`
	Notes     string   `json:"notes"`
}

An ExportEntry object represents a database record prepared for export.

Jump to

Keyboard shortcuts

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