Documentation ¶
Overview ¶
Package kaliber implements a server for the `Calibre` library software.
Copyright © 2019, 2020 M.Watermann, 10247 Berlin, Germany All rights reserved EMail : <support@mwat.de>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the GNU General Public License along with this program. If not, see the [GNU General Public License](http://www.gnu.org/licenses/gpl.html) for details.
Index ¶
- Variables
- func AddUser(aUser, aFilename string)
- func BookFieldVisible(aFieldname string) (bool, error)
- func CalibreCachePath() string
- func CalibreLibraryPath() string
- func CalibrePreferencesFile() string
- func CheckUser(aUser, aFilename string)
- func DeleteUser(aUser, aFilename string)
- func InitConfig()
- func ListUsers(aFilename string)
- func MetaFieldValue(aSection, aField string) (interface{}, error)
- func OpenDatabase() error
- func RemoveWhiteSpace(aPage []byte) []byte
- func SQLtraceFile() string
- func SetCalibreCachePath(aPath string)
- func SetCalibreLibraryPath(aPath string) string
- func SetSQLtraceFile(aFilename string)
- func SetThumbWidth(aWidth uint) uint
- func ShowHelp()
- func ThumbWidth() uint
- func Thumbnail(aDoc *TDocument) (string, error)
- func ThumbnailUpdate()
- func URLparts(aURL string) (rDir, rPath string)
- func UpdateUser(aUser, aFilename string)
- func VirtLibOptions(aSelected string) string
- type TCustomColumn
- type TCustomColumnList
- type TDocList
- type TDocument
- func (doc *TDocument) AuthorList() string
- func (doc *TDocument) Authors() *TEntityList
- func (doc *TDocument) Comment() template.HTML
- func (doc *TDocument) Cover() string
- func (doc *TDocument) CoverFile() (string, error)
- func (doc *TDocument) DocLink() string
- func (doc *TDocument) Filename(aFormat string) string
- func (doc *TDocument) Files() *TEntityList
- func (doc *TDocument) Formats() *TEntityList
- func (doc *TDocument) Identifiers() *TEntityList
- func (doc *TDocument) Languages() *TEntityList
- func (doc *TDocument) PubDate() string
- func (doc *TDocument) Publisher() *TEntity
- func (doc *TDocument) Series() *TEntity
- func (doc *TDocument) SeriesIndex() string
- func (doc *TDocument) Tags() *TEntityList
- func (doc *TDocument) Thumb() string
- func (doc *TDocument) Timestamp() string
- type TEntity
- type TEntityList
- type TID
- type TPageHandler
- type TQueryOptions
- func (qo *TQueryOptions) DecLimit() *TQueryOptions
- func (qo *TQueryOptions) IncLimit() *TQueryOptions
- func (qo *TQueryOptions) Scan(aString string) *TQueryOptions
- func (qo *TQueryOptions) SelectLanguageOptions() *TStringMap
- func (qo *TQueryOptions) SelectLayoutOptions() *TStringMap
- func (qo *TQueryOptions) SelectLimitOptions() string
- func (qo *TQueryOptions) SelectOrderOptions() *TStringMap
- func (qo *TQueryOptions) SelectSortByOptions() *TStringMap
- func (qo *TQueryOptions) SelectThemeOptions() *TStringMap
- func (qo *TQueryOptions) SelectVirtLibOptions() string
- func (qo *TQueryOptions) String() string
- func (qo *TQueryOptions) Update(aRequest *http.Request) *TQueryOptions
- type TSearch
- type TSortType
- type TStringMap
- type TView
- type TViewList
- type TVirtLibList
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
var ( // AppArguments is the merged list for the cmdline arguments // and INI values for the application. AppArguments tArguments )
Functions ¶
func AddUser ¶
func AddUser(aUser, aFilename string)
AddUser reads a password for `aUser` from the commandline and adds it to `aFilename`.
NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.
`aUser` the username to add to the password file. `aFilename` name of the password file to use.
func BookFieldVisible ¶ added in v0.13.0
BookFieldVisible returns whether `aFieldname` should be visible or not.
If `aFieldname` can't be found the function returns `true` and an error, otherwise the (boolean) `visible` value and `nil`.
`aFieldname` The name of the field/column to check.
func CalibreCachePath ¶
func CalibreCachePath() string
CalibreCachePath returns the directory of the copied `Calibre` databse.
func CalibreLibraryPath ¶
func CalibreLibraryPath() string
CalibreLibraryPath returns the base directory of the `Calibre` library.
func CalibrePreferencesFile ¶ added in v0.9.0
func CalibrePreferencesFile() string
CalibrePreferencesFile returns the complete path-/filename of the `Calibre` library's preferences file.
func CheckUser ¶
func CheckUser(aUser, aFilename string)
CheckUser reads a password for `aUser` from the commandline and compares it with the one stored in `aFilename`.
NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.
`aUser` the username to check in the password file. `aFilename` name of the password file to use.
func DeleteUser ¶
func DeleteUser(aUser, aFilename string)
DeleteUser removes the entry for `aUser` from the password list `aFilename`.
NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.
`aUser` the username to remove from the password file. `aFilename` name of the password file to use.
func InitConfig ¶ added in v0.12.0
func InitConfig()
InitConfig reads the commandline arguments into a list structure merging it with key-value pairs read from INI file(s).
The steps here are:
(a) read the INI file(s), (b) merge the commandline arguments with the INI values
into the global `AppArguments` variable.
func ListUsers ¶ added in v0.13.4
func ListUsers(aFilename string)
ListUsers reads `aFilename` and lists all users stored in there.
NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.
`aFilename` name of the password file to use.
func MetaFieldValue ¶ added in v0.13.0
MetaFieldValue returns the value of `aField` of `aSection`.
aSection Name of the field's metadata section. aField Name of the data field within `aSection`.
func OpenDatabase ¶ added in v0.12.1
func OpenDatabase() error
OpenDatabase establishes a new database connection.
func RemoveWhiteSpace ¶
RemoveWhiteSpace removes HTML comments and unnecessary whitespace.
This function removes all unneeded/redundant whitespace and HTML comments from the given `aPage`. This can reduce significantly the amount of data to send to the remote user agent thus saving bandwidth and time.
`aPage` The HTML document to process.
func SQLtraceFile ¶ added in v0.4.7
func SQLtraceFile() string
SQLtraceFile returns the optional file used for logging all SQL queries.
func SetCalibreCachePath ¶
func SetCalibreCachePath(aPath string)
SetCalibreCachePath sets the directory of the `Calibre` database copy.
`aPath` is the directory path to use for caching the Calibre library.
func SetCalibreLibraryPath ¶
SetCalibreLibraryPath sets the base directory of the `Calibre` library.
`aPath` is the directory path where the Calibre library resides.
func SetSQLtraceFile ¶ added in v0.4.7
func SetSQLtraceFile(aFilename string)
SetSQLtraceFile sets the filename to use for logging SQL queries.
If the provided `aFilename` is empty the SQL logging gets disabled.
`aFilename` the tracefile to use; if empty tracing is disabled.
func SetThumbWidth ¶ added in v0.2.0
SetThumbWidth set the new width for generated thumbnails.
If `aWidth` is smaller than `64` it's increased.
func ThumbWidth ¶ added in v0.2.0
func ThumbWidth() uint
ThumbWidth returns the configured width of generated thumbnails.
func ThumbnailUpdate ¶ added in v0.2.0
func ThumbnailUpdate()
ThumbnailUpdate creates thumbnails for all existing documents
func URLparts ¶
URLparts returns two parts: `rDir` holds the base-directory of `aURL`, `rPath` holds the remaining part of `aURL`.
Depending on the actual value of `aURL` both return values may be empty or both may be filled; none of both will hold a leading slash.
func UpdateUser ¶
func UpdateUser(aUser, aFilename string)
UpdateUser reads a password for `aUser` from the commandline and updates the entry in the password list `aFilename`.
NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.
`aUser` the username to remove from the password file.
`aFilename` name of the password file to use.
func VirtLibOptions ¶ added in v0.13.0
VirtLibOptions returns the SELECT/OPTIONs of the virtual libraries.
aSelected Name of the currently selected library.
Types ¶
type TCustomColumn ¶ added in v0.11.4
TCustomColumn contains info about a user-defined data field.
type TCustomColumnList ¶ added in v0.11.4
type TCustomColumnList []TCustomColumn
TCustomColumnList is a list/slice of `TCustomColumnRec`.
func QueryCustomColumns ¶ added in v0.11.4
func QueryCustomColumns() (*TCustomColumnList, error)
QueryCustomColumns returns data about user-defined columns in `Calibre`.
type TDocList ¶
type TDocList []TDocument
TDocList is a list of `TDocument` instances.
func NewDocList ¶ added in v0.13.0
func NewDocList() *TDocList
NewDocList returns a new `TDocList` instance.
func QueryBy ¶
func QueryBy(aOptions *TQueryOptions) (rCount int, rList *TDocList, rErr error)
QueryBy returns all documents according to `aOptions`.
The function returns in `rCount` the number of documents found, in `rList` either `nil` or a list list of documents, in `rErr` either `nil` or an error occurred during the search.
`aOptions` The options to configure the query.
func QueryIDs ¶ added in v0.2.0
QueryIDs returns a list of documents with only the `ID` and `path` fields set.
This function is used by `thumbnails`.
func QuerySearch ¶
func QuerySearch(aOptions *TQueryOptions) (rCount int, rList *TDocList, rErr error)
QuerySearch returns a list of documents.
The function returns in `rCount` the number of documents found, in `rList` either `nil` or a list list of documents, in `rErr` either `nil` or an error occurred during the search.
`aOptions` The options to configure the query.
type TDocument ¶
type TDocument struct { ID TID ISBN string Pages int Rating int Size int64 Title string // contains filtered or unexported fields }
TDocument represents a single document (e.g. book)
func NewDocument ¶ added in v0.13.0
func NewDocument() *TDocument
NewDocument returns a new `TDocument` instance.
func QueryDocMini ¶
QueryDocMini returns the document identified by `aID`.
This function fills only the document fields `ID`, `formats`, `path`, and `Title`.
`aID` The document ID to lookup.
func QueryDocument ¶
QueryDocument returns the `TDocument` identified by `aID`.
`aID` The document ID to lookup.
func (*TDocument) AuthorList ¶ added in v0.13.0
AuthorList returns a CSV list of the document's author(s).
func (*TDocument) Authors ¶
func (doc *TDocument) Authors() *TEntityList
Authors returns a list of ID/Name/URL author fields.
func (*TDocument) CoverFile ¶ added in v0.10.0
CoverFile returns the complete path/filename of the document's cover file.
func (*TDocument) Files ¶
func (doc *TDocument) Files() *TEntityList
Files returns a list of ID/Name/URL fields for doc format files.
func (*TDocument) Formats ¶
func (doc *TDocument) Formats() *TEntityList
Formats returns a list of ID/Name/URL fields for doc formats.
func (*TDocument) Identifiers ¶
func (doc *TDocument) Identifiers() *TEntityList
Identifiers returns a list of ID/Name/URL identifier fields.
func (*TDocument) Languages ¶ added in v0.13.0
func (doc *TDocument) Languages() *TEntityList
Languages returns an ID/Name/URL language struct.
func (*TDocument) SeriesIndex ¶
SeriesIndex returns the document's series index as formatted string.
func (*TDocument) Tags ¶
func (doc *TDocument) Tags() *TEntityList
Tags returns a list of ID/Name/URL tag fields.
type TEntity ¶
type TEntity struct { ID TID // database row ID Name string // name of the column/field URL string // local URL to access this entity }
TEntity is a basic entity structure.
type TPageHandler ¶
type TPageHandler struct {
// contains filtered or unexported fields
}
TPageHandler provides the handling of HTTP request/response.
func NewPageHandler ¶
func NewPageHandler() (*TPageHandler, error)
NewPageHandler returns a new `TPageHandler` instance.
func (*TPageHandler) Address ¶
func (ph *TPageHandler) Address() string
Address returns the configured `IP:Port` address to use for listening.
func (*TPageHandler) GetErrorPage ¶
func (ph *TPageHandler) GetErrorPage(aData []byte, aStatus int) []byte
GetErrorPage returns an error page for `aStatus`, implementing the `TErrorPager` interface.
func (*TPageHandler) NeedAuthentication ¶
func (ph *TPageHandler) NeedAuthentication(aRequest *http.Request) bool
NeedAuthentication returns `true` if authentication is needed, or `false` otherwise.
`aRequest` is the request to check.
func (*TPageHandler) ServeHTTP ¶
func (ph *TPageHandler) ServeHTTP(aWriter http.ResponseWriter, aRequest *http.Request)
ServeHTTP handles the incoming HTTP requests.
type TQueryOptions ¶
type TQueryOptions struct { ID TID // an entity ID to lookup Descending bool // sort direction Entity string // query for a certain entity (authors, publisher, series, tags) GuiLang uint8 // GUI language Layout uint8 // either `qoLayoutList` or `qoLayoutGrid` LimitLength uint // number of documents per page LimitStart uint // starting number Matching string // text to lookup in all documents QueryCount uint // number of DB records matching the query options SortBy TSortType // display order of documents (`qoSortByXXX`) Theme uint8 // CSS presentation theme VirtLib string // virtual libraries }
TQueryOptions hold properties configuring a query.
This type is used by the HTTP pagehandler when receiving a page's data.
func NewQueryOptions ¶
func NewQueryOptions() *TQueryOptions
NewQueryOptions returns a new `TQueryOptions` instance.
func (*TQueryOptions) DecLimit ¶
func (qo *TQueryOptions) DecLimit() *TQueryOptions
DecLimit decrements the LIMIT values.
func (*TQueryOptions) IncLimit ¶
func (qo *TQueryOptions) IncLimit() *TQueryOptions
IncLimit increments the LIMIT values.
func (*TQueryOptions) Scan ¶
func (qo *TQueryOptions) Scan(aString string) *TQueryOptions
Scan returns the options read from `aString`.
func (*TQueryOptions) SelectLanguageOptions ¶ added in v0.5.1
func (qo *TQueryOptions) SelectLanguageOptions() *TStringMap
SelectLanguageOptions returns a list of two SELECT/OPTIONs.
func (*TQueryOptions) SelectLayoutOptions ¶ added in v0.3.0
func (qo *TQueryOptions) SelectLayoutOptions() *TStringMap
SelectLayoutOptions returns a list of SELECT/OPTIONs.
func (*TQueryOptions) SelectLimitOptions ¶
func (qo *TQueryOptions) SelectLimitOptions() string
SelectLimitOptions returns a list of SELECT/OPTIONs.
func (*TQueryOptions) SelectOrderOptions ¶
func (qo *TQueryOptions) SelectOrderOptions() *TStringMap
SelectOrderOptions returns a list of SELECT/OPTIONs.
func (*TQueryOptions) SelectSortByOptions ¶
func (qo *TQueryOptions) SelectSortByOptions() *TStringMap
SelectSortByOptions returns a list of SELECT/OPTIONs.
func (*TQueryOptions) SelectThemeOptions ¶ added in v0.5.0
func (qo *TQueryOptions) SelectThemeOptions() *TStringMap
SelectThemeOptions returns a list of two SELECT/OPTIONs.
func (*TQueryOptions) SelectVirtLibOptions ¶ added in v0.7.0
func (qo *TQueryOptions) SelectVirtLibOptions() string
SelectVirtLibOptions returns the SELECT/OPTIONs of virtual libraries.
func (*TQueryOptions) String ¶
func (qo *TQueryOptions) String() string
String returns the options as a `|` delimited string.
func (*TQueryOptions) Update ¶
func (qo *TQueryOptions) Update(aRequest *http.Request) *TQueryOptions
Update returns a `TQueryOptions` instance with updated values read from the `aRequest` data.
type TSearch ¶
type TSearch struct {
// contains filtered or unexported fields
}
TSearch provides text search capabilities.
type TStringMap ¶
TStringMap is a map of strings indexed by string.
type TView ¶
type TView struct {
// contains filtered or unexported fields
}
TView combines a template and its logical name.
func NewView ¶
NewView returns a new `TView` with `aName`.
`aBaseDir` is the path to the directory storing the template files. `aName` is the name of the template file providing the page's main
body without the filename extension (i.e. w/o ".gohtml"). `aName` serves as both the main template's name as well as the view's name.
func (*TView) Render ¶
func (v *TView) Render(aWriter http.ResponseWriter, aData *TemplateData) error
Render executes the template using the TView's properties.
`aWriter` is a http.ResponseWriter, or e.g. `os.Stdout` in console apps. `aData` is a list of data to be injected into the template.
If an error occurs executing the template or writing its output, execution stops, and the method returns without writing anything to the output `aWriter`.
func (*TView) RenderedPage ¶
func (v *TView) RenderedPage(aData *TemplateData) ([]byte, error)
RenderedPage returns the rendered template/page and a possible Error executing the template.
`aData` is a list of data to be injected into the template.
type TViewList ¶
type TViewList tViewList
TViewList is a list of `TView` instances (to be used as a template pool).
func NewViewList ¶
func NewViewList() *TViewList
NewViewList returns a new (empty) `TViewList` instance.
func (*TViewList) Add ¶
Add appends `aView` to the list.
`aView` is the view to add to this list.
The view's name (as specified in the `NewView()` function call) is used as the view's key in this list.
func (*TViewList) Get ¶
Get returns the view with `aName`.
`aName` is the name (key) of the `TView` object to retrieve.
If `aName` doesn't exist, the return value is `nil`. The second value (ok) is a `bool` that is `true` if `aName` exists in the list, and `false` if not.
func (*TViewList) Render ¶
func (vl *TViewList) Render(aName string, aWriter http.ResponseWriter, aData *TemplateData) error
Render executes the template with the key `aName`.
`aName` is the name of the template/view to use. `aWriter` is a `http.ResponseWriter` to handle the executed template. `aData` is a list of data to be injected into the template.
If an error occurs executing the template or writing its output, execution stops, and the method returns without writing anything to the output `aWriter`.
func (*TViewList) RenderedPage ¶
func (vl *TViewList) RenderedPage(aName string, aData *TemplateData) ([]byte, error)
RenderedPage returns the rendered template/page with the key `aName`.
`aName` is the name of the template/view to use. `aData` is a list of data to be injected into the template.
type TVirtLibList ¶ added in v0.13.0
TVirtLibList is the `virtual_libraries` JSON metadata section.
func VirtualLibraryList ¶ added in v0.13.0
func VirtualLibraryList() (TVirtLibList, error)
VirtualLibraryList returns a list of virtual library definitions and SQL code to access them.
type TemplateData ¶
type TemplateData map[string]interface{}
TemplateData is a list of values to be injected into a template.
func NewTemplateData ¶
func NewTemplateData() *TemplateData
NewTemplateData returns a new (empty) `TDataList` instance.
func (*TemplateData) Set ¶
func (dl *TemplateData) Set(aKey string, aValue interface{}) *TemplateData
Set inserts `aValue` identified by `aKey` to the list.
If there's already a list entry with `aKey` its current value gets replaced by `aValue`.
`aKey` is the values's identifier (as used as placeholder in the template).
`aValue` contains the data entry's value.