core

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2019 License: GPL-3.0 Imports: 18 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConfigFilename is the name of the config file
	ConfigFilename = "dnoterc"
	// TmpContentFilename is the name of the temporary file that holds editor input
	TmpContentFilename = "DNOTE_TMPCONTENT"
)

Functions

func CheckUpdate added in v0.4.2

func CheckUpdate(ctx infra.DnoteCtx) error

CheckUpdate triggers update if needed

func DeleteSystem added in v0.6.0

func DeleteSystem(db *infra.DB, key string) error

DeleteSystem delets the given system record

func GetBookUUID added in v0.4.5

func GetBookUUID(ctx infra.DnoteCtx, label string) (string, error)

GetBookUUID returns a uuid of a book given a label

func GetCipherKey added in v0.6.0

func GetCipherKey(ctx infra.DnoteCtx) ([]byte, error)

GetCipherKey retrieves the cipher key and decode the base64 into bytes.

func GetConfigPath

func GetConfigPath(ctx infra.DnoteCtx) string

GetConfigPath returns the path to the dnote config file

func GetDnoteTmpContentPath

func GetDnoteTmpContentPath(ctx infra.DnoteCtx) string

GetDnoteTmpContentPath returns the path to the temporary file containing content being added or edited

func GetEditorInput

func GetEditorInput(ctx infra.DnoteCtx, fpath string, content *string) error

GetEditorInput gets the user input by launching a text editor and waiting for it to exit

func GetSystem added in v0.6.0

func GetSystem(db *infra.DB, key string, dest interface{}) error

GetSystem scans the given system configuration record onto the destination

func GetValidSession added in v0.6.0

func GetValidSession(ctx infra.DnoteCtx) (string, bool, error)

GetValidSession returns a session key from the local storage if one exists and is not expired If one does not exist or is expired, it prints out an instruction and returns false

func InitFiles added in v0.4.3

func InitFiles(ctx infra.DnoteCtx) error

InitFiles creates, if necessary, the dnote directory and files inside

func InitSystem added in v0.4.9

func InitSystem(ctx infra.DnoteCtx) error

InitSystem inserts system data if missing

func InsertSystem added in v0.6.0

func InsertSystem(db *infra.DB, key, val string) error

InsertSystem inserets a system configuration

func LogAction

func LogAction(tx *sql.Tx, schema int, actionType, data string, timestamp int64) error

LogAction logs action and updates the last_action

func ReadConfig

func ReadConfig(ctx infra.DnoteCtx) (infra.Config, error)

ReadConfig reads the config file

func SanitizeContent

func SanitizeContent(s string) string

SanitizeContent sanitizes note content

func UpdateSystem added in v0.6.0

func UpdateSystem(db *infra.DB, key, val interface{}) error

UpdateSystem updates a system configuration

func UpsertSystem added in v0.6.0

func UpsertSystem(db *infra.DB, key, val string) error

UpsertSystem inserts or updates a system configuration

func WriteConfig

func WriteConfig(ctx infra.DnoteCtx, config infra.Config) error

WriteConfig writes the config to the config file

Types

type Book added in v0.4.9

type Book struct {
	UUID    string `json:"uuid"`
	Label   string `json:"label"`
	USN     int    `json:"usn"`
	Notes   []Note `json:"notes"`
	Deleted bool   `json:"deleted"`
	Dirty   bool   `json:"dirty"`
}

Book holds a metadata and its notes

func NewBook

func NewBook(uuid, label string, usn int, deleted, dirty bool) Book

NewBook constructs a book with the given data

func (Book) Expunge added in v0.4.9

func (b Book) Expunge(db *infra.DB) error

Expunge hard-deletes the book from the database

func (Book) Insert added in v0.4.9

func (b Book) Insert(db *infra.DB) error

Insert inserts a new book

func (Book) Update added in v0.4.9

func (b Book) Update(db *infra.DB) error

Update updates the book with the given data

func (*Book) UpdateUUID added in v0.4.9

func (b *Book) UpdateUUID(db *infra.DB, newUUID string) error

UpdateUUID updates the uuid of a book

type Note added in v0.4.9

type Note struct {
	UUID     string `json:"uuid"`
	BookUUID string `json:"book_uuid"`
	Body     string `json:"content"`
	AddedOn  int64  `json:"added_on"`
	EditedOn int64  `json:"edited_on"`
	USN      int    `json:"usn"`
	Public   bool   `json:"public"`
	Deleted  bool   `json:"deleted"`
	Dirty    bool   `json:"dirty"`
}

Note represents a note

func NewNote

func NewNote(uuid, bookUUID, body string, addedOn, editedOn int64, usn int, public, deleted, dirty bool) Note

NewNote constructs a note with the given data

func (Note) Expunge added in v0.4.9

func (n Note) Expunge(db *infra.DB) error

Expunge hard-deletes the note from the database

func (Note) Insert added in v0.4.9

func (n Note) Insert(db *infra.DB) error

Insert inserts a new note

func (Note) Update added in v0.4.9

func (n Note) Update(db *infra.DB) error

Update updates the note with the given data

func (*Note) UpdateUUID added in v0.4.9

func (n *Note) UpdateUUID(db *infra.DB, newUUID string) error

UpdateUUID updates the uuid of a book

type RunEFunc

type RunEFunc func(*cobra.Command, []string) error

RunEFunc is a function type of dnote commands

Jump to

Keyboard shortcuts

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