Documentation ¶
Overview ¶
Package box provides a generic interface to zettel boxes.
Index ¶
- Variables
- func DoNotEnrich(ctx context.Context) bool
- func GetNewZid(testZid func(id.Zid) (bool, error)) (id.Zid, error)
- func GetQueryBool(u *url.URL, key string) bool
- func GetQueryInt(u *url.URL, key string, min, def, max int) int
- func NewErrNotAllowed(op string, user *meta.Meta, zid id.Zid) error
- func NoEnrichContext(ctx context.Context) context.Context
- func NoEnrichQuery(ctx context.Context, q *query.Query) context.Context
- type BaseBox
- type Box
- type Enricher
- type ErrInvalidZid
- type ErrNotAllowed
- type ErrZettelNotFound
- type ManagedBox
- type ManagedBoxStats
- type Manager
- type MetaFunc
- type Refresher
- type StartState
- type StartStopper
- type Stats
- type Subject
- type UpdateFunc
- type UpdateInfo
- type UpdateReason
- type WriteBox
- type ZidFunc
Constants ¶
This section is empty.
Variables ¶
var ErrCapacity = errors.New("capacity exceeded")
ErrCapacity is returned if a box has reached its capacity.
var ErrConflict = errors.New("conflict")
ErrConflict is returned if a box operation detected a conflict.. One example: if calculating a new zettel identifier takes too long.
var ErrReadOnly = errors.New("read-only box")
ErrReadOnly is returned if there is an attepmt to write to a read-only box.
var ErrStarted = errors.New("box is already started")
ErrStarted is returned when trying to start an already started box.
var ErrStopped = errors.New("box is stopped")
ErrStopped is returned if calling methods on a box that was not started.
Functions ¶
func DoNotEnrich ¶
DoNotEnrich determines if the context is marked to not enrich metadata.
func GetNewZid ¶
GetNewZid calculates a new and unused zettel identifier, based on the current date and time.
func GetQueryBool ¶ added in v0.5.0
GetQueryBool is a helper function to extract bool values from a box URI.
func GetQueryInt ¶ added in v0.5.0
GetQueryInt is a helper function to extract int values of a specified range from a box URI.
func NewErrNotAllowed ¶
NewErrNotAllowed creates an new authorization error.
func NoEnrichContext ¶
NoEnrichContext will signal an enricher that nothing has to be done. This is useful for an Indexer, but also for some box.Box calls, when just the plain metadata is needed.
Types ¶
type BaseBox ¶
type BaseBox interface { // Location returns some information where the box is located. // Format is dependent of the box. Location() string // GetZettel retrieves a specific zettel. GetZettel(ctx context.Context, zid id.Zid) (zettel.Zettel, error) // AllowRenameZettel returns true, if box will not disallow renaming the zettel. AllowRenameZettel(ctx context.Context, zid id.Zid) bool // RenameZettel changes the current Zid to a new Zid. RenameZettel(ctx context.Context, curZid, newZid id.Zid) error // CanDeleteZettel returns true, if box could possibly delete the given zettel. CanDeleteZettel(ctx context.Context, zid id.Zid) bool // DeleteZettel removes the zettel from the box. DeleteZettel(ctx context.Context, zid id.Zid) error }
BaseBox is implemented by all Zettel boxes.
type Box ¶
type Box interface { BaseBox WriteBox // FetchZids returns the set of all zettel identifer managed by the box. FetchZids(ctx context.Context) (id.Set, error) // GetMeta returns the metadata of the zettel with the given identifier. GetMeta(context.Context, id.Zid) (*meta.Meta, error) // SelectMeta returns a list of metadata that comply to the given selection criteria. // If `metaSeq` is `nil`, the box assumes metadata of all available zettel. SelectMeta(ctx context.Context, metaSeq []*meta.Meta, q *query.Query) ([]*meta.Meta, error) // GetAllZettel retrieves a specific zettel from all managed boxes. GetAllZettel(ctx context.Context, zid id.Zid) ([]zettel.Zettel, error) // Refresh the data from the box and from its managed sub-boxes. Refresh(context.Context) error // ReIndex one zettel to update its index data. ReIndex(context.Context, id.Zid) error }
Box is to be used outside the box package and its descendants.
type Enricher ¶
type Enricher interface { // Enrich computes additional properties and updates the given metadata. // It is typically called by zettel reading methods. Enrich(ctx context.Context, m *meta.Meta, boxNumber int) }
Enricher is used to update metadata by adding new properties.
type ErrInvalidZid ¶ added in v0.14.0
type ErrInvalidZid struct{ Zid string }
ErrInvalidZid is returned if the zettel id is not appropriate for the box operation.
func (ErrInvalidZid) Error ¶ added in v0.14.0
func (err ErrInvalidZid) Error() string
type ErrNotAllowed ¶
ErrNotAllowed is returned if the caller is not allowed to perform the operation.
func (*ErrNotAllowed) Error ¶
func (err *ErrNotAllowed) Error() string
func (*ErrNotAllowed) Is ¶
func (*ErrNotAllowed) Is(error) bool
Is return true, if the error is of type ErrNotAllowed.
type ErrZettelNotFound ¶ added in v0.14.0
ErrZettelNotFound is returned if a zettel was not found in the box.
func (ErrZettelNotFound) Error ¶ added in v0.14.0
func (eznf ErrZettelNotFound) Error() string
type ManagedBox ¶
type ManagedBox interface { BaseBox // HasZettel returns true, if box conains zettel with given identifier. HasZettel(context.Context, id.Zid) bool // Apply identifier of every zettel to the given function, if predicate returns true. ApplyZid(context.Context, ZidFunc, query.RetrievePredicate) error // Apply metadata of every zettel to the given function, if predicate returns true. ApplyMeta(context.Context, MetaFunc, query.RetrievePredicate) error // ReadStats populates st with box statistics ReadStats(st *ManagedBoxStats) }
ManagedBox is the interface of managed boxes.
type ManagedBoxStats ¶
type ManagedBoxStats struct { // ReadOnly indicates that the content of a box cannot change. ReadOnly bool // Zettel is the number of zettel managed by the box. Zettel int }
ManagedBoxStats records statistics about the box.
type Manager ¶
type Manager interface { Box StartStopper Subject // ReadStats populates st with box statistics ReadStats(st *Stats) // Dump internal data to a Writer. Dump(w io.Writer) }
Manager is a box-managing box.
type StartState ¶ added in v0.11.0
type StartState uint8
StartState enumerates the possible states of starting and stopping a box.
StartStateStopped -> StartStateStarting -> StartStateStarted -> StateStateStopping -> StartStateStopped.
Other transitions are also possible.
const ( StartStateStopped StartState = iota StartStateStarting StartStateStarted StartStateStopping )
Constant values of StartState
type StartStopper ¶
type StartStopper interface { // State the current status of the box. State() StartState // Start the box. Now all other functions of the box are allowed. // Starting a box, which is not in state StartStateStopped is not allowed. Start(ctx context.Context) error // Stop the started box. Now only the Start() function is allowed. Stop(ctx context.Context) }
StartStopper performs simple lifecycle management.
type Stats ¶
type Stats struct { // ReadOnly indicates that boxes cannot be modified. ReadOnly bool // NumManagedBoxes is the number of boxes managed. NumManagedBoxes int // Zettel is the number of zettel managed by the box, including // duplicates across managed boxes. ZettelTotal int // LastReload stores the timestamp when a full re-index was done. LastReload time.Time // DurLastReload is the duration of the last full re-index run. DurLastReload time.Duration // IndexesSinceReload counts indexing a zettel since the full re-index. IndexesSinceReload uint64 // ZettelIndexed is the number of zettel managed by the indexer. ZettelIndexed int // IndexUpdates count the number of metadata updates. IndexUpdates uint64 // IndexedWords count the different words indexed. IndexedWords uint64 // IndexedUrls count the different URLs indexed. IndexedUrls uint64 }
Stats record stattistics about a box.
type Subject ¶
type Subject interface { // RegisterObserver registers an observer that will be notified // if one or all zettel are found to be changed. RegisterObserver(UpdateFunc) }
Subject is a box that notifies observers about changes.
type UpdateFunc ¶
type UpdateFunc func(UpdateInfo)
UpdateFunc is a function to be called when a change is detected.
type UpdateInfo ¶
type UpdateInfo struct { Box BaseBox Reason UpdateReason Zid id.Zid }
UpdateInfo contains all the data about a changed zettel.
type UpdateReason ¶
type UpdateReason uint8
UpdateReason gives an indication, why the ObserverFunc was called.
const ( OnReady UpdateReason // Box is started and fully operational OnReload // Box was reloaded OnZettel // Something with a zettel happened )
Values for Reason
type WriteBox ¶ added in v0.15.0
type WriteBox interface { // CanCreateZettel returns true, if box could possibly create a new zettel. CanCreateZettel(ctx context.Context) bool // CreateZettel creates a new zettel. // Returns the new zettel id (and an error indication). CreateZettel(ctx context.Context, zettel zettel.Zettel) (id.Zid, error) // CanUpdateZettel returns true, if box could possibly update the given zettel. CanUpdateZettel(ctx context.Context, zettel zettel.Zettel) bool // UpdateZettel updates an existing zettel. UpdateZettel(ctx context.Context, zettel zettel.Zettel) error }
WriteBox is a box that can create / update zettel content.
Directories ¶
Path | Synopsis |
---|---|
Package compbox provides zettel that have computed content.
|
Package compbox provides zettel that have computed content. |
Package constbox puts zettel inside the executable.
|
Package constbox puts zettel inside the executable. |
Package dirbox provides a directory-based zettel box.
|
Package dirbox provides a directory-based zettel box. |
Package filebox provides boxes that are stored in a file.
|
Package filebox provides boxes that are stored in a file. |
Package manager coordinates the various boxes and indexes of a Zettelstore.
|
Package manager coordinates the various boxes and indexes of a Zettelstore. |
mapstore
Package mapstore stored the index in main memory via a Go map.
|
Package mapstore stored the index in main memory via a Go map. |
store
Package store contains general index data for storing a zettel index.
|
Package store contains general index data for storing a zettel index. |
Package membox stores zettel volatile in main memory.
|
Package membox stores zettel volatile in main memory. |
Package notify provides some notification services to be used by box services.
|
Package notify provides some notification services to be used by box services. |