Documentation ¶
Overview ¶
Package kaliber implements a server for the `Calibre` library software.
Copyright © 2019 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 ¶
- Constants
- Variables
- func AddUser(aUser, aFilename string)
- func CalibreCachePath() string
- func CalibreDatabaseName() string
- func CalibreDatabasePath() string
- func CalibreLibraryPath() string
- func CheckUser(aUser, aFilename string)
- func DBopen(aFilename string) error
- func DeleteUser(aUser, aFilename string)
- func ListUser(aFilename string)
- func RemoveWhiteSpace(aPage []byte) []byte
- func SetCalibreCachePath(aPath string) string
- func SetCalibreLibraryPath(aPath string) string
- func ShowHelp()
- func URLparts(aURL string) (rDir, rPath string)
- func UpdateUser(aUser, aFilename string)
- type TDocList
- type TDocument
- func (doc *TDocument) Authors() *TEntityList
- func (doc *TDocument) Comment() template.HTML
- func (doc *TDocument) Cover() string
- func (doc *TDocument) DocLink() string
- func (doc *TDocument) Filename(aFormat string) string
- func (doc *TDocument) Filenames() *TPathList
- func (doc *TDocument) Files() *TEntityList
- func (doc *TDocument) Formats() *TEntityList
- func (doc *TDocument) Identifiers() *TEntityList
- func (doc *TDocument) Language() *TEntity
- 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) Timestamp() string
- type TEntity
- type TEntityList
- type TID
- type TPageHandler
- type TPathList
- type TQueryOptions
- func (qo *TQueryOptions) CGI() string
- func (qo *TQueryOptions) DecLimit() *TQueryOptions
- func (qo *TQueryOptions) IncLimit() *TQueryOptions
- func (qo *TQueryOptions) Scan(aString string) *TQueryOptions
- func (qo *TQueryOptions) SelectLimitOptions() *TStringMap
- func (qo *TQueryOptions) SelectOrderOptions() *TStringMap
- func (qo *TQueryOptions) SelectSortByOptions() *TStringMap
- func (qo *TQueryOptions) String() string
- func (qo *TQueryOptions) UnCGI(aCGI string) *TQueryOptions
- func (qo *TQueryOptions) Update(aRequest *http.Request) *TQueryOptions
- type TSearch
- type TStringMap
- type TView
- type TViewList
- type TemplateData
Constants ¶
const ( SortUnsorted = uint8(iota) SortByAuthor SortByLanguage SortByPublisher SortByRating SortBySeries SortBySize SortByTags SortByTime SortByTitle )
Constants defining the ORDER_BY clause
Variables ¶
var (
// AppArguments is the list for the cmdline arguments and INI values.
AppArguments tAguments
)
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 CalibreCachePath ¶
func CalibreCachePath() string
CalibreCachePath returns the directory of the copied `Calibre` databse.
func CalibreDatabaseName ¶
func CalibreDatabaseName() string
CalibreDatabaseName returns the name of the `Calibre` database.
func CalibreDatabasePath ¶
func CalibreDatabasePath() string
CalibreDatabasePath returns rhe complete path-/filename of the `Calibre` library.
func CalibreLibraryPath ¶
func CalibreLibraryPath() string
CalibreLibraryPath returns the base directory of the `Calibre` library.
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 DBopen ¶
DBopen establishes a new database connection.
`aFilename` is the path-/filename of the SQLite database 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 ListUser ¶
func ListUser(aFilename string)
ListUser 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 RemoveWhiteSpace ¶
RemoveWhiteSpace removes HTML comments and unneccessary whitespace.
This function removes all unneeded/redundant whitespace and HTML comments from the given <tt>aPage</tt>. This can reduce significantly the amount of data to send to the remote user agent thus saving bandwidth.
func SetCalibreCachePath ¶
SetCalibreCachePath sets the directory of the `Calibre` database copy.
func SetCalibreLibraryPath ¶
SetCalibreLibraryPath sets the base directory of the `Calibre` library.
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.
Types ¶
type TDocList ¶
type TDocList []TDocument
TDocList is a list of `TDocument` instances.
func QueryBy ¶
func QueryBy(aOption *TQueryOptions) (rCount int, rList *TDocList, rErr error)
QueryBy returns all documents according to `aOption`.
func QueryLimit ¶
QueryLimit returns a list of `TDocument` objects.
func QuerySearch ¶
func QuerySearch(aOption *TQueryOptions) (rCount int, rList *TDocList, rErr error)
QuerySearch returns a list of documents
type TDocument ¶
type TDocument tDocument
TDocument represents a single document (e.g. book)
func QueryDocMini ¶
QueryDocMini returns the document identified by `aID`.
This function fills only the document fields `ID`, `formats`, `path`, `authorSort`, and `Title`.
func QueryDocument ¶
QueryDocument returns the `TDocument` identified by `aID`.
func (*TDocument) Authors ¶
func (doc *TDocument) Authors() *TEntityList
Authors returns a list of ID/Name author fields.
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) 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 tag fields.
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 TPathList ¶
type TPathList TStringMap
TPathList is a map of document formats holding the respective library file.
type TQueryOptions ¶
type TQueryOptions struct { ID TID // an entity ID to lookup Descending bool // sort direction Entity string // limiting query to a certain entity (author,publisher, series, tag) LimitLength uint // number of documents per page LimitStart uint // starting number Matching string // text to lookup in all documents SortBy uint8 // display order of documents QueryCount uint // number of DB records matching the query option }
TQueryOptions holds 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) CGI ¶
func (qo *TQueryOptions) CGI() string
CGI returns the object's query escaped string representation fit for use as the `qos` CGI argument.
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) SelectLimitOptions ¶
func (qo *TQueryOptions) SelectLimitOptions() *TStringMap
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) String ¶
func (qo *TQueryOptions) String() string
String returns the options as a `|` delimited string.
func (*TQueryOptions) UnCGI ¶
func (qo *TQueryOptions) UnCGI(aCGI string) *TQueryOptions
UnCGI unescapes the given `aCGI`.
If there are errors during unescaping the current values remain unchanged.
func (*TQueryOptions) Update ¶
func (qo *TQueryOptions) Update(aRequest *http.Request) *TQueryOptions
Update returns a `TQueryOptions` instance with 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) (rBytes []byte, rErr 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) (rBytes []byte, rErr 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 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.