Documentation ¶
Index ¶
- Constants
- Variables
- func AddNewCredential(store UserCredentialStore, name, secret string, credType CredentialType) error
- func ChangeTitle(db Storager, ns NotestoreClient, old, new string) error
- func CreateAndEditNewNote(client *Client, note *Note, opts NoteOption) error
- func CreateNotebook(ns NotestoreClient, notebook *Notebook, defaultNotebook bool) error
- func DeleteNote(db Storager, ns NotestoreClient, title, notebook string) error
- func EditNote(client *Client, title string, opts NoteOption) error
- func MoveNote(db Storager, ns NotestoreClient, noteTitle, notebookName string) error
- func RemoveCredential(store UserCredentialStore, name string) error
- func RemoveCredentialByIndex(store UserCredentialStore, index int) error
- func SaveChanges(ns NotestoreClient, n *Note, opts NoteOption) error
- func SaveNewNote(ns NotestoreClient, n *Note, raw bool) error
- func UpdateNotebook(db Storager, ns NotestoreClient, name string, notebook *Notebook) error
- func WriteCredentialListing(w io.Writer, creds []*Credential)
- func WriteCredentialListingWithSecret(w io.Writer, creds []*Credential)
- func WriteNote(w io.Writer, n *Note, opts NoteOption) error
- func WriteNoteListing(w io.Writer, ns []*Note, nbs []*Notebook)
- func WriteNotebookListing(w io.Writer, nbs []*Notebook)
- func WriteSettingsListing(w io.Writer, vals, args, desc []string)
- type CacheFile
- type Client
- type ClientOption
- type Configuration
- type Credential
- type CredentialType
- type DefaultConfig
- type Editer
- type EnvEditor
- type FileCacheFile
- type MemoryCacheFile
- type Note
- type NoteFilter
- type NoteOption
- type Notebook
- type NotebookCacheList
- type NotestoreClient
- type Settings
- type Storager
- type UserCredentialStore
- type VimEditor
Constants ¶
const ( // DefaultClientOptions creates a client with default options. DefaultClientOptions ClientOption = 0 // EvernoteSandbox tells the client to use Evernote's sandbox instead of production. EvernoteSandbox = 1 << iota // MemoryBasedCacheFile for using a ram based file for editing. MemoryBasedCacheFile // VimEditer for using Vim as the editor. VimEditer )
const ( // DefaultNoteOption will display or edit the note with default options. DefaultNoteOption NoteOption = 0 // RawNote option will display or edit the note in it's raw format. RawNote = 1 << iota // UseRecoveryPointNote should be used to signal that the user wants to // reopen the note that the note store failed to save. UseRecoveryPointNote )
const (
// XMLHeader is the header that needs to added to the note content.
XMLHeader = `<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">`
)
Variables ¶
var ( // ErrNoMatchingCredentialFound is returned if no matching credential is found. ErrNoMatchingCredentialFound = errors.New("no matching credential found") // ErrNegativeIndex is returned if index is negative ErrNegativeIndex = errors.New("index negative") // ErrIndexToBig is returned if index is greater than the list. ErrIndexToBig = errors.New("index greater than the array") )
var ( // NoteFilterOrderCreated sorts the notes by create time. NoteFilterOrderCreated = int32(1) // NoteFilterOrderUpdated sorts the notes by update time. NoteFilterOrderUpdated = int32(2) // NoteFilterOrderRelevance sorts the notes by relevance. NoteFilterOrderRelevance = int32(3) // NoteFilterOrderSequenceNumber sorts the notes by sequence number. NoteFilterOrderSequenceNumber = int32(4) // NoteFilterOrderTitle sorts the notes by title. NoteFilterOrderTitle = int32(5) )
var ( // ErrNoNotebookFound is returned if no matching notebook was found. ErrNoNotebookFound = errors.New("no notebook found") // ErrNoNotebookCached is returned when trying to update a notebook // that hasn't been pulled from the server. ErrNoNotebookCached = errors.New("no notebook found") )
var ( // DefaultNotebookCacheTime is the default time limit for when the // list is considered outdated. DefaultNotebookCacheTime = 24 * time.Hour )
var ( // ErrNoEditorFound is returned if no editor was found. ErrNoEditorFound = errors.New("no editor found") )
var ( // ErrNoNoteFound is returned if search resulted in no notes found. ErrNoNoteFound = errors.New("no note found") )
Functions ¶
func AddNewCredential ¶ added in v0.5.0
func AddNewCredential(store UserCredentialStore, name, secret string, credType CredentialType) error
AddNewCredential creates and add a new credential to the store.
func ChangeTitle ¶
func ChangeTitle(db Storager, ns NotestoreClient, old, new string) error
ChangeTitle changes the note's title.
func CreateAndEditNewNote ¶ added in v0.5.0
func CreateAndEditNewNote(client *Client, note *Note, opts NoteOption) error
CreateAndEditNewNote creates a new note and opens it in the client's editor. Once the editor has been closed, the note is saved to the notestore.
func CreateNotebook ¶
func CreateNotebook(ns NotestoreClient, notebook *Notebook, defaultNotebook bool) error
CreateNotebook creates a new notebook.
func DeleteNote ¶
func DeleteNote(db Storager, ns NotestoreClient, title, notebook string) error
DeleteNote moves a note from the notebook to the trash can.
func EditNote ¶ added in v0.5.0
func EditNote(client *Client, title string, opts NoteOption) error
EditNote opens the editor so the user can edit the note. Once the user closes the editor, the note is saved to the notestore.
func MoveNote ¶
func MoveNote(db Storager, ns NotestoreClient, noteTitle, notebookName string) error
MoveNote moves the note to a new notebook.
func RemoveCredential ¶ added in v0.5.0
func RemoveCredential(store UserCredentialStore, name string) error
RemoveCredential removes the first credential with the matching name.
func RemoveCredentialByIndex ¶ added in v0.5.0
func RemoveCredentialByIndex(store UserCredentialStore, index int) error
RemoveCredentialByIndex removes the credential at the index provided.
func SaveChanges ¶
func SaveChanges(ns NotestoreClient, n *Note, opts NoteOption) error
SaveChanges updates the changes to the note on the server.
func SaveNewNote ¶
func SaveNewNote(ns NotestoreClient, n *Note, raw bool) error
SaveNewNote pushes the new note to the server.
func UpdateNotebook ¶
func UpdateNotebook(db Storager, ns NotestoreClient, name string, notebook *Notebook) error
UpdateNotebook updates the notebook.
func WriteCredentialListing ¶ added in v0.5.0
func WriteCredentialListing(w io.Writer, creds []*Credential)
WriteCredentialListing creates and writes a credential listing table using the writer.
func WriteCredentialListingWithSecret ¶ added in v0.5.0
func WriteCredentialListingWithSecret(w io.Writer, creds []*Credential)
WriteCredentialListingWithSecret creates and writes a credential listing table using the writer.
func WriteNote ¶ added in v0.5.0
func WriteNote(w io.Writer, n *Note, opts NoteOption) error
WriteNote writes the note using the provided writer.
func WriteNoteListing ¶ added in v0.5.0
WriteNoteListing creates and writes a note listing table using the writer.
func WriteNotebookListing ¶ added in v0.5.0
WriteNotebookListing creates and writes a notebook listing table using the writer.
func WriteSettingsListing ¶ added in v0.5.0
WriteSettingsListing writes the settings table to writer.
Types ¶
type CacheFile ¶ added in v0.5.0
type CacheFile interface { io.ReadWriteCloser FilePath() string ReOpen() error CloseAndRemove() error }
CacheFile has the note content written and the user edits the content in the CacheFile to update the note's content.
type Client ¶ added in v0.5.0
type Client struct { // Config is the systems configuration Config Configuration // Store is the storage client Store Storager // Notestore is a client to interact with the note store. NoteStore NotestoreClient // Editor is the editor. Editor Editer // contains filtered or unexported fields }
Client is a client for all note operations.
func NewClient ¶ added in v0.5.0
func NewClient(config Configuration, store Storager, ns NotestoreClient, opts ClientOption) *Client
NewClient creates a new Client struct.
type ClientOption ¶ added in v0.5.0
type ClientOption int32
ClientOption is an bit mask of options for the client.
type Configuration ¶
type Configuration interface { io.Closer // GetConfigFolder returns the folder used to store configurations. GetConfigFolder() string // GetCacheFolder returns the cache folder. GetCacheFolder() string // Store returns the backend storage. Store() Storager // UserStore returns the user storage. UserStore() UserCredentialStore }
Configuration is the interface for a configuration struct.
type Credential ¶ added in v0.5.0
type Credential struct { // Name is the user given name for the credential. Name string // Secret is used to authenticate to the note store. Secret string // CredType is used to identify credential type. CredType CredentialType }
Credential is a struct that holds credential information.
func GetAllCredentials ¶ added in v0.5.0
func GetAllCredentials(store UserCredentialStore) ([]*Credential, error)
GetAllCredentials returns all the credentials in the store.
func GetCredential ¶ added in v0.5.0
func GetCredential(store UserCredentialStore, index int) (*Credential, error)
GetCredential returns the credential with the matching index.
type CredentialType ¶ added in v0.5.0
type CredentialType uint8
CredentialType is a type of credential. Used to identify which backend to use
const ( // EvernoteCredential is used for credentials that can authenticate with Evernote. EvernoteCredential CredentialType = iota // EvernoteSandboxCredential is used for credentials that can authenticate with // Evernote's sandbox server. EvernoteSandboxCredential )
func (CredentialType) String ¶ added in v0.5.0
func (c CredentialType) String() string
type DefaultConfig ¶
type DefaultConfig struct { // DB is the backend storage for the client. DB Storager // UDB is the backend storage for user credentials. UDB UserCredentialStore }
DefaultConfig uses shared config and cache folder with other instances of DefaultConfig structs.
func (*DefaultConfig) Close ¶
func (c *DefaultConfig) Close() error
Close closes the BoltDB handler.
func (*DefaultConfig) GetCacheFolder ¶
func (*DefaultConfig) GetCacheFolder() string
GetCacheFolder returns the folder used to cache.
func (*DefaultConfig) GetConfigFolder ¶
func (*DefaultConfig) GetConfigFolder() string
GetConfigFolder returns the folder used to store configurations.
func (*DefaultConfig) Store ¶
func (c *DefaultConfig) Store() Storager
Store returns a handler to BoltDB.
func (*DefaultConfig) UserStore ¶ added in v0.5.0
func (c *DefaultConfig) UserStore() UserCredentialStore
UserStore returns a handler to BoltDB.
type EnvEditor ¶ added in v0.5.0
type EnvEditor struct{}
EnvEditor opens the note the note using the program defined in the environment variable $EDITOR.
type FileCacheFile ¶ added in v0.5.0
type FileCacheFile struct {
// contains filtered or unexported fields
}
FileCacheFile implements the CacheFile interface and uses a temporary file for storing the data on disk.
func (*FileCacheFile) Close ¶ added in v0.5.0
func (f *FileCacheFile) Close() error
Close closes the file. This should be called before the file is edited by the editor.
func (*FileCacheFile) CloseAndRemove ¶ added in v0.5.0
func (f *FileCacheFile) CloseAndRemove() error
CloseAndRemove closes the file and removes it.
func (*FileCacheFile) FilePath ¶ added in v0.5.0
func (f *FileCacheFile) FilePath() string
FilePath returns the absolute path to the temporary file.
func (*FileCacheFile) ReOpen ¶ added in v0.5.0
func (f *FileCacheFile) ReOpen() error
ReOpen opens the file again after it's been closed. This should be called after the file has been edited.
type MemoryCacheFile ¶ added in v0.5.0
type MemoryCacheFile struct {
// contains filtered or unexported fields
}
MemoryCacheFile is a memory based representation of a cache file.
func (*MemoryCacheFile) Close ¶ added in v0.5.0
func (m *MemoryCacheFile) Close() error
Close handles the close call.
func (*MemoryCacheFile) CloseAndRemove ¶ added in v0.5.0
func (m *MemoryCacheFile) CloseAndRemove() error
CloseAndRemove deletes the named FIFO pipe.
func (*MemoryCacheFile) FilePath ¶ added in v0.5.0
func (m *MemoryCacheFile) FilePath() string
FilePath returns the path to the FIFO pipe that should be used to send and receive data to and from the Editer.
func (*MemoryCacheFile) ReOpen ¶ added in v0.5.0
func (m *MemoryCacheFile) ReOpen() error
ReOpen handles the ReOpen call.
type Note ¶
type Note struct { // Title is the note tile. Title string // GUID is the unique identifier. GUID string // Body contains the body of the note. Body string `xml:",innerxml"` // MD is a Markdown representation of the note body. MD string // Deleted is set true if the note is marked for deletion. Deleted bool // Notebook the note belongs to. Notebook *Notebook // Created Created int64 // Updated Updated int64 }
Note is the structure of an Evernote note.
func FindNotes ¶
func FindNotes(ns NotestoreClient, filter *NoteFilter, offset int, count int) ([]*Note, error)
FindNotes searches for notes.
func GetNote ¶
func GetNote(db Storager, ns NotestoreClient, title, notebook string) (*Note, error)
GetNote gets the note metadata in the notebook from the server. If the notebook is an empty string, the first matching note will be returned.
func GetNoteWithContent ¶
func GetNoteWithContent(db Storager, ns NotestoreClient, title string) (*Note, error)
GetNoteWithContent returns the note with content from the user's notestore.
type NoteFilter ¶
type NoteFilter struct { // NotebookGUID is the GUID for the notebook to limit the search to. NotebookGUID string // Words can be a search string or note title. Words string // Order Order int32 }
NoteFilter is the search filter for notes.
type NoteOption ¶ added in v0.5.0
type NoteOption int32
NoteOption are used for options around notes.
type Notebook ¶
type Notebook struct { // Name is the notebook's name Name string // GUID is the notebook's GUID. GUID string // Stack is the stack that the notebook belongs too. Stack string }
Notebook is a struct for the notebook.
func FindNotebook ¶
func FindNotebook(db Storager, ns NotestoreClient, name string) (*Notebook, error)
FindNotebook gets the notebook matching with the name. If no notebook is found, nil is returned.
func GetNotebook ¶
func GetNotebook(ns NotestoreClient, guid string) (*Notebook, error)
GetNotebook returns a notebook from the user's notestore.
func GetNotebooks ¶
func GetNotebooks(db Storager, ns NotestoreClient, forceSync bool) ([]*Notebook, error)
GetNotebooks returns all the user's notebooks.
type NotebookCacheList ¶
type NotebookCacheList struct { // Notebooks is the list of notebooks. Notebooks []*Notebook // Timestamp of when the list was created. Timestamp time.Time // Limit is the until the list outdated. Limit time.Duration }
NotebookCacheList is a list of cached notebooks.
func NewNotebookCacheList ¶
func NewNotebookCacheList(notebooks []*Notebook) *NotebookCacheList
NewNotebookCacheList creates a cache list with the default expiration limit.
func NewNotebookCacheListWithLimit ¶
func NewNotebookCacheListWithLimit(notebooks []*Notebook, limit time.Duration) *NotebookCacheList
NewNotebookCacheListWithLimit creates a new cache list with the given expiration limit.
func (*NotebookCacheList) IsOutdated ¶
func (n *NotebookCacheList) IsOutdated() bool
IsOutdated returns true if the list has expired.
type NotestoreClient ¶
type NotestoreClient interface { // FindNotes searches for the notes based on the filter. FindNotes(filter *NoteFilter, offset, count int) ([]*Note, error) // GetAllNotebooks returns all the of users notebooks. GetAllNotebooks() ([]*Notebook, error) // GetNotebook GetNotebook(guid string) (*Notebook, error) // CreateNotebook CreateNotebook(b *Notebook, defaultNotebook bool) error // GetNoteContent gets the note's content from the notestore. GetNoteContent(guid string) (string, error) // UpdateNote update's the note. UpdateNote(note *Note) error // DeleteNote removes a note from the user's notebook. DeleteNote(guid string) error // CreateNote creates a new note on the server. CreateNote(note *Note) error // UpdateNotebook updates the notebook on the server. UpdateNotebook(book *Notebook) error }
NotestoreClient is the interface for the notestore.
type Settings ¶
type Settings struct { // APIKey is the user's session key. APIKey string // Credential holds the user's credential data. Credential *Credential }
Settings is a struct holding the user's settings for the application.
type Storager ¶
type Storager interface { io.Closer GetSettings() (*Settings, error) StoreSettings(*Settings) error // GetNotebookCache returns the stored NotebookCacheList. GetNotebookCache() (*NotebookCacheList, error) // StoreNotebookList saves the list to the database. StoreNotebookList(list *NotebookCacheList) error // SaveSearch stores a note search to the database. SaveSearch([]*Note) error // GetSearch returns a saved note search from the database. GetSearch() ([]*Note, error) // SaveNoteRecoveryPoint saves the note as a recovery point. SaveNoteRecoveryPoint(*Note) error // GetNoteREcoveryPoint returns the saved note. GetNoteRecoveryPoint() (*Note, error) }
Storager is the interface for backend storage.
type UserCredentialStore ¶ added in v0.5.0
type UserCredentialStore interface { // Add saves a new credential to the store. Add(*Credential) error // Remove deletes a credential from the store. Remove(*Credential) error // GetAll returns all credentials in the store. GetAll() ([]*Credential, error) // GetByIndex returns a user credential by its index. GetByIndex(index int) (*Credential, error) }
UserCredentialStore provides an interface to a backend that stores a user's credentials.