Documentation
¶
Index ¶
- func DefaultConfigPath() string
- func EnsureConfigFile(path string) error
- func SaveConfig(path string, uc *UserConfig) error
- type Anki
- type AnkiAudio
- type Consumer
- type ConsumerFunc
- type Dictionary
- type Jisho
- type Manager
- type Part
- type Reloader
- type SaveFailedError
- type UpdateConfigFunc
- type UserConfig
- type Wadoku
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultConfigPath ¶
func DefaultConfigPath() string
func EnsureConfigFile ¶
EnsureConfigFile checks that file on path exists and if not, writes default config
func SaveConfig ¶
func SaveConfig(path string, uc *UserConfig) error
Types ¶
type Anki ¶
type Anki struct {
// Addr is host:port of AnkiConnect address.
// Protocol must not be specified, anyway https seems to be redudant.
Addr string `yaml:"addr" koanf:"addr"`
// APIKey is secret that can be enabled on AnkiConnect.
// Can be any string. Empty string means that no secret will be used.
APIKey string `yaml:"api-key" koanf:"api-key"`
// Deck is the name of deck in Anki where new cards will be added.
// Deck can be any non-empty string, that doesn't contain `"` (Anki removes it),
// that doesn't start or end with spaces.
// I have found that Anki can convert some names with `::`, for example name
// `hello::::world` will have alias `hello::blank::world`, but this should not
// break anything.
Deck string `yaml:"deck" koanf:"deck"`
// NoteType is the name of note type that will be used for creation new notes in Anki.
// NoteType can be any non-empty string, that doesn't contain `"` (Anki removes it) and
// doesn't start or end with spaces.
NoteType string `yaml:"note-type" koanf:"note-type"`
// FieldMapping specifies how note fields will be filled in new notes.
//
// Key is the name of field in Anki. Can be any non-empty string that doesn't contain
// symbols `:`, `"`, `{` or `}` and doesn't start or end with spaces.
//
// Value should be valid go text/template. For more details see pkg/anki/template.go.
FieldMapping map[string]string `yaml:"fields" koanf:"fields"`
// Audio specifies how audio should be mapped to anki notes.
Audio AnkiAudio `yaml:"audio" koanf:"audio"`
}
type Consumer ¶
type Consumer interface {
// Config extracts parts of config that will be used.
// Also its recommended that you implement validation in this function.
Config(*UserConfig) (Part, error)
}
type ConsumerFunc ¶
type ConsumerFunc func(*UserConfig) (Part, error)
ConsumerFunc is helper implementation for Consumer interface
func (ConsumerFunc) Config ¶
func (f ConsumerFunc) Config(uc *UserConfig) (Part, error)
type Dictionary ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) Current ¶
func (m *Manager) Current() *UserConfig
func (*Manager) Register ¶
func (m *Manager) Register(consumer Consumer) (Part, UpdateConfigFunc, error)
Register registers config consumer. It's not concurrent safe. If consumer implement Reloader interface then it will be registered as consumer that can reload it's self on config change. Also Reloader gets it's initial reload with acquired part.
func (*Manager) UpdateConfig ¶
func (m *Manager) UpdateConfig(updateFn func(*UserConfig) error) error
UpdateConfig guarded by simple mutex. This function will rewrite config specified while construction Manager. Saving can be failed despite reloading all affected parts, this indicated by SaveFailedError.
type SaveFailedError ¶
type SaveFailedError struct {
Reason error
}
func (*SaveFailedError) Error ¶
func (e *SaveFailedError) Error() string
func (*SaveFailedError) Unwrap ¶
func (e *SaveFailedError) Unwrap() error
type UpdateConfigFunc ¶
type UpdateConfigFunc func(updateFn func(*UserConfig) error) error
type UserConfig ¶
type UserConfig struct {
Addr string `yaml:"addr" koanf:"addr"`
Anki Anki `yaml:"anki" koanf:"anki"`
Dictionary Dictionary `yaml:"dictionary" koanf:"dictionary"`
}
func DefaultUserConfig ¶
func DefaultUserConfig() *UserConfig
func LoadConfig ¶
func LoadConfig(path string) (*UserConfig, error)
func (*UserConfig) Clone ¶
func (uc *UserConfig) Clone() *UserConfig
Click to show internal directories.
Click to hide internal directories.