notes

package module
v0.0.0-...-f74c09a Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2021 License: MIT Imports: 7 Imported by: 0

README

README

This project is merely for demonstration purposes and is not intended to be used in production.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

type Book struct {
	Logger io.Writer // Logger for verbose logging
	// contains filtered or unexported fields
}

A Book allows for management, such as inserting, updating, and deleting notes.

func (*Book) Backup

func (book *Book) Backup(w io.Writer) error

Backup backs up the book, in JSON, to the provided writer.

func (*Book) Delete

func (book *Book) Delete(ids ...int) error

Delete removes the given notes from the book, if they exist.

func (*Book) Insert

func (book *Book) Insert(notes ...*Note) error

Insert adds the given notes to the book.

func (*Book) Len

func (book *Book) Len() int

Len returns the number of notes in the book.

func (*Book) MarshalJSON

func (book *Book) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the book.

func (*Book) Restore

func (book *Book) Restore(r io.Reader) error

Restore restores the book from the provided reader. The reader should contain a JSON-encoded book.

func (*Book) Select

func (book *Book) Select(ids ...int) ([]*Note, error)

Select returns the notes that match the given ids. If no ids are given, all notes are returned.

func (*Book) UnmarshalJSON

func (book *Book) UnmarshalJSON(data []byte) error

UnmarshalJSON parses the JSON-encoded data and stores the result in the book.

func (*Book) Update

func (book *Book) Update(notes ...*Note) error

Update updates the given notes in the book.

type ErrNotFound

type ErrNotFound int

ErrNotFound is returned when a note is not found.

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

type Note

type Note struct {
	Body string `json:"body,omitempty"` // The body of the note.
	// contains filtered or unexported fields
}

A Note is a single entry in a book.

func (*Note) CreatedAt

func (note *Note) CreatedAt() time.Time

CreatedAt returns the time the note was created.

func (*Note) ID

func (note *Note) ID() int

ID returns the ID of the note.

func (*Note) IsValid

func (note *Note) IsValid() bool

IsValid returns true if the note body is present

func (*Note) MarshalJSON

func (note *Note) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the note.

func (*Note) Short

func (note *Note) Short(i int) string

Short returns a truncated version of the note body. If the body is less than the specified length, the whole body is returned. Newlines are escaped. "\\n"

func (*Note) String

func (note *Note) String() string

String returns a human readable representation of the note.

func (*Note) UnmarshalJSON

func (note *Note) UnmarshalJSON(data []byte) error

UnmarshalJSON parses the JSON-encoded data and stores the result in the note.

func (*Note) UpdatedAt

func (note *Note) UpdatedAt() time.Time

UpdatedAt returns the time the note was last updated.

Jump to

Keyboard shortcuts

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