Documentation
¶
Index ¶
- Variables
- type Collection
- type Datastore
- func (d *Datastore) AddItemTag(cid string, t Tag) error
- func (d *Datastore) AddItemToCollection(cid string, ipns string) error
- func (d *Datastore) AddItemToFolder(cid string, folder *Folder) error
- func (d *Datastore) Close() error
- func (d *Datastore) CreateOrUpdateCollection(c *Collection) error
- func (d *Datastore) CreateOrUpdateFolder(folder *Folder) error
- func (d *Datastore) CreateOrUpdateItem(i *Item) error
- func (d *Datastore) DelCollection(ipns string) error
- func (d *Datastore) DelFolder(folder *Folder) error
- func (d *Datastore) DelItem(cid string) error
- func (d *Datastore) HasTag(cid string, t Tag) (bool, error)
- func (d *Datastore) IsCollectionEmpty(ipns string) (bool, error)
- func (d *Datastore) IsFolderPathExists(ipns, path string) (bool, error)
- func (d *Datastore) IsItemInCollection(cid string, ipns string) (bool, error)
- func (d *Datastore) IsItemInFolder(cid string, folder *Folder) (bool, error)
- func (d *Datastore) ListCollections(mineFlag, emptyFlag FilterFlag) ([]*Collection, error)
- func (d *Datastore) MoveOrCopyFolder(folderFrom, folderTo *Folder, copy bool) error
- func (d *Datastore) MoveOrCopyItem(cid string, folderFrom, folderTo *Folder, copy bool) error
- func (d *Datastore) ReadCollection(ipns string) (*Collection, error)
- func (d *Datastore) ReadCollectionItems(ipns string) ([]string, error)
- func (d *Datastore) ReadFolder(ipns, path string) (*Folder, error)
- func (d *Datastore) ReadFolderChildren(folder *Folder) ([]string, error)
- func (d *Datastore) ReadFolderItems(folder *Folder) ([]string, error)
- func (d *Datastore) ReadItem(cid string) (*Item, error)
- func (d *Datastore) ReadTagItemCount(tags []Tag) ([]uint, error)
- func (d *Datastore) RemoveItemFromCollection(cid string, ipns string) error
- func (d *Datastore) RemoveItemFromFolder(cid string, folder *Folder) error
- func (d *Datastore) RemoveItemTag(cid string, t Tag) error
- func (d *Datastore) SearchTags(prefix string) ([]Tag, error)
- type FilterFlag
- type Folder
- type Item
- type Tag
Constants ¶
This section is empty.
Variables ¶
var ( // ErrIPNSNotFound is returned when an IPNS is not found in Datastore. ErrIPNSNotFound = errors.New("IPNS not found") // ErrCIDNotFound is returned when a CID is not found in Datastore. ErrCIDNotFound = errors.New("CID not found") // ErrNegativeTagItemCount is returned when the value of tag::[tagStr] in Datastore is negative. ErrNegativeTagItemCount = errors.New("Negative tag item count") // ErrFolderNotExists is returned when folder doesn't exist. ErrFolderNotExists = errors.New("Folder doesn't exist") // ErrParentFolderNotExists is returned when parent folder doesn't exist. ErrParentFolderNotExists = errors.New("Parent folder doesn't exist") // ErrItemNotInFolder is returned when the item is not in the folder. ErrItemNotInFolder = errors.New("Item is not in the folder") // ErrItemInCollection is returned when the item is already in the collection. ErrItemInCollection = errors.New("Item is already in the collection") // ErrCantDelRootFolder is returned when trying to delete a root folder. ErrCantDelRootFolder = errors.New("Root folder can't be deleted") )
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection struct { IPNSAddress string // Can be either a IPNS hash or a DNSLink domain Name string Description string IsMine bool }
Collection is a collection of resource Items. TODO: Last update timestamp
type Datastore ¶
type Datastore struct {
// contains filtered or unexported fields
}
Datastore is a store for saving resource collections data. Including collections and their resource items. For now it is a struct using BadgerDB. Later on it will be refactored as an interface with multiple database implements. Key-Values:
collections_all::[ipns] = [ipns] collections_mine::[ipns] = [ipns] collections_others::[ipns] = [ipns] collection::[ipns]::name collection::[ipns]::description collection::[ipns]::ismine collection_item::[ipns]::[cid] = [cid] folders::[ipns]::[folderPath] = [folderPath] # The folderPath of root folder is "" folder::[ipns]::[folderPath]::children = [listOfChildFolderNames] folder_item::[ipns]::[folderPath]::[cid] = [cid] items::[cid] = [cid] item::[cid]::name item_collection::[cid]::[ipns] = [ipns] item_tag::[cid]::[tagStr] = [tagStr] item_folder::[cid]::[ipns]::[folderPath] = [folderPath] tags::[tagStr] = [tagStr] tag::[tagStr].count = [itemCount] tag_item::[tagStr]::[cid] = [cid]
func NewDatastore ¶
NewDatastore creates a new Datastore.
func (*Datastore) AddItemTag ¶
AddItemTag adds a Tag to an Item. If the tag doesn't exist in database, it will be created.
func (*Datastore) AddItemToCollection ¶
AddItemToCollection adds an Item to a Collection.
func (*Datastore) AddItemToFolder ¶
AddItemToFolder adds an item to a folder
func (*Datastore) CreateOrUpdateCollection ¶
func (d *Datastore) CreateOrUpdateCollection(c *Collection) error
CreateOrUpdateCollection update collection information
func (*Datastore) CreateOrUpdateFolder ¶
CreateOrUpdateFolder creates a new folder or updates a folder
func (*Datastore) CreateOrUpdateItem ¶
CreateOrUpdateItem update collection information
func (*Datastore) DelCollection ¶
DelCollection deletes a collection from datastore. Deleting a collection won't delete items that belongs to the collection.
func (*Datastore) DelFolder ¶
DelFolder deletes a folder and all its children folders. It also remove relationships with items. Items won't be deleted. If an item doesn't belong to any folder of the collection, it will be removed from the collection.
func (*Datastore) IsCollectionEmpty ¶
func (*Datastore) IsFolderPathExists ¶
IsFolderPathExists checkes if a folder exists.
func (*Datastore) IsItemInCollection ¶
IsItemInCollection checks if an Item belongs to a Collection.
func (*Datastore) IsItemInFolder ¶
IsItemInFolder checks if an item is in a folder
func (*Datastore) ListCollections ¶
func (d *Datastore) ListCollections(mineFlag, emptyFlag FilterFlag) ([]*Collection, error)
ListCollections list collections
func (*Datastore) MoveOrCopyFolder ¶
MoveOrCopyFolder moves or copies a folder to destination
func (*Datastore) MoveOrCopyItem ¶
MoveOrCopyItem moves or copies an item from a folder to another folder
func (*Datastore) ReadCollection ¶
func (d *Datastore) ReadCollection(ipns string) (*Collection, error)
ReadCollection reads Collection data from database.
func (*Datastore) ReadCollectionItems ¶
ReadCollectionItems returns all items' CID in a collection
func (*Datastore) ReadFolder ¶
ReadFolder reads a folder from Datastore.
func (*Datastore) ReadFolderChildren ¶
ReadFolderChildren returns all children (sub-folders) in a folder
func (*Datastore) ReadFolderItems ¶
ReadFolderItems returns all items' CID in a folder
func (*Datastore) ReadTagItemCount ¶
ReadTagItemCount returns []uint that are item counts of []Tag
func (*Datastore) RemoveItemFromCollection ¶
RemoveItemFromCollection removes an Item from a Collection.
func (*Datastore) RemoveItemFromFolder ¶
RemoveItemFromFolder removes item from a folder
func (*Datastore) RemoveItemTag ¶
RemoveItemTag removes a Tag from an Item.
type FilterFlag ¶
type FilterFlag int
const ( FilterOnly FilterFlag = 1 FilterAny FilterFlag = 0 FilterNone FilterFlag = -1 )
type Folder ¶
Folder belongs to only one collection. It may have a parent folder and multiple sub folders. In one collection, a Folder's path is unique. If path is "", it's the root directory of a collection TODO: Total file size of resources that the folder contains. Including subfolders. TODO: Last update timestamp
func (*Folder) ParentPath ¶
ParentPath return parent paths of the folder
type Tag ¶
type Tag []string
Tag is for tagging Items.
func NewTagFromStr ¶
NewTagFromStr create new Tag struct from a string.