Documentation ¶
Overview ¶
Package kaliber implements a server for the `Calibre` library software.
Copyright © 2019, 2023 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.
----
NOTE: While formally this is a library (`package`) in reality it's sort of a toolbox for the `main` package (the file of which is in the `app` sub-directory). In other words: this library is not supposed to be imported into other projects.
The publicly documented functions and methods are an arbitrary selection. In fact, most of the functionality of this `library` is implemented in private functions. Most of the `public` functions/methods are only public because they may be called from outside the source code file they were written in.
For a real understanding you're encouraged to read the source code and the comments therein.
Index ¶
- func InitConfig()
- func ListUsers(aFilename string)
- func SetThumbWidth(aWidth uint) uint
- func ShowHelp()
- func ThumbWidth() uint
- func Thumbnail(aDoc *db.TDocument) (string, error)
- func ThumbnailUpdate()
- func URLparts(aURL string) (rDir, rPath string)
- func UserAdd(aUser, aFilename string)
- func UserCheck(aUser, aFilename string)
- func UserDelete(aUser, aFilename string)
- func UserUpdate(aUser, aFilename string)
- type TAppArgs
- type TPageHandler
- type TView
- type TViewList
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitConfig ¶ added in v0.12.0
func InitConfig()
InitConfig sets up and reads all configuration data from INI file(s) and commandline arguments.
The steps here are:
(1) read the INI file(s):
(a) read the local `./.kaliber.ini` (b) read the global `/etc/kaliber.ini` (c) read the user-local `~/.kaliber.ini` (d) read the user-local `~/.config/kaliber.ini`
(2) merge the commandline arguments with the INI values into the global `AppArgs` variable.
This function is meant to be called first thing in the application's `main()` function.
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 SetThumbWidth ¶ added in v0.2.0
SetThumbWidth set the new width for generated thumbnails.
If `aWidth` is smaller than `64` it's increased to `64`.
`aWidth` The new thumbnail width to use.
func ThumbWidth ¶ added in v0.2.0
func ThumbWidth() uint
ThumbWidth returns the configured width of generated thumbnails.
func Thumbnail ¶ added in v0.2.0
Thumbnail generates a thumbnail of the document's cover.
`aDoc` The document to check the thumbnail for.
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.
`aURL` The address to split up.
func UserAdd ¶ added in v0.27.0
func UserAdd(aUser, aFilename string)
UserAdd 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 UserCheck ¶ added in v0.27.0
func UserCheck(aUser, aFilename string)
UserCheck 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 UserDelete ¶ added in v0.27.0
func UserDelete(aUser, aFilename string)
UserDelete 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 UserUpdate ¶ added in v0.27.0
func UserUpdate(aUser, aFilename string)
UserUpdate 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 TAppArgs ¶ added in v0.27.0
type TAppArgs struct { AccessLog string // (optional) name of page access logfile Addr string // listen address ("1.2.3.4:5678") AuthAll bool // authenticate user for all pages and documents BooksPerPage int // number of documents shown per web-page CertKey string // TLS certificate key CertPem string // private TLS certificate DataDir string // base directory of application's data ErrorLog string // (optional) name of page error logfile GZip bool // send compressed data to remote browser // Intl string // path/filename of the localisation file Lang string // default GUI language LibName string // the library's name LogStack bool // log stack trace in case of errors PassFile string // (optional) name of page access logfile Realm string // host/domain to secure by BasicAuth SessionDir string // directory for session data Theme string // `dark` or `light` display theme UserAdd string // username to add to password list UserCheck string // username to check in password list UserDelete string // username to delete from password list UserList bool // print out a list of current users UserUpdate string // username to update in password list // contains filtered or unexported fields }
TAppArgs Collection of commandline arguments and INI values.
var ( // AppArgs Commandline arguments and INI values. // // This structure should be considered R/O after it was // set up by a call to `InitConfig()`. AppArgs TAppArgs )
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) GetErrorPage ¶
func (ph *TPageHandler) GetErrorPage(aData []byte, aStatus int) []byte
GetErrorPage returns an error page for `aStatus`, implementing the `TErrorPager` interface.
`aData` The original error text. `aStatus` The number of the actual HTTP error status.
func (*TPageHandler) NeedAuthentication ¶
func (ph *TPageHandler) NeedAuthentication(aRequest *http.Request) bool
NeedAuthentication returns `true` if authentication is needed, or `false` otherwise.
This method implements the `passlist.TAuthDecider` interface.
`aRequest` The web request to check.
func (*TPageHandler) ServeHTTP ¶
func (ph *TPageHandler) ServeHTTP(aWriter http.ResponseWriter, aRequest *http.Request)
ServeHTTP handles the incoming HTTP requests.
`aWriter` Used by the HTTP handler to construct an HTTP response. `aRequest` The HTTP request received by the server.
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 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.