Documentation ¶
Overview ¶
Copyright © 2020, 2024 M.Watermann, 10247 Berlin, Germany
All rights reserved EMail : <support@mwat.de>
Package nele implements a simple blog-server.
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.
Copyright © 2019, 2024 M.Watermann, 10247 Berlin, Germany
All rights reserved EMail : <support@mwat.de>
Index ¶
- Variables
- func AddConsolePost() (int, error)
- func AddFilePost(aFilename string) (int, error)
- func AddTagID(aList *ht.THashTags, aPosting *TPosting)
- func CreateScreenshot(aURL string)
- func InitConfig()
- func InitHashlist(aList *ht.THashTags)
- func MDtoHTML(aMarkdown []byte) (rHTML []byte)
- func MarkupCloud(aList *ht.THashTags) []template.HTML
- func MarkupTags(aPage []byte) []byte
- func PostingBaseDirectory() string
- func PrepareLinkScreenshots(aPosting *TPosting)
- func ReadHashlist(aList *ht.THashTags)
- func RemoveIDTags(aList *ht.THashTags, aID uint64)
- func RemovePageScreenshots(aPosting *TPosting)
- func RenameIDTags(aList *ht.THashTags, aOldID, aNewID uint64)
- func ReplaceTag(aList *ht.THashTags, aSearchTag, aReplaceTag string)
- func SetPersistence(aPersistence IPersistence)
- func SetPostingBaseDirectory(aBaseDir string) error
- func ShowHelp()
- func URLparts(aURL string) (rPath, rTail string, rID uint64)
- func UpdateScreenshots()
- func UpdateTags(aList *ht.THashTags, aPosting *TPosting)
- func UserAdd(aUser, aFilename string)
- func UserCheck(aUser, aFilename string)
- func UserDelete(aUser, aFilename string)
- func UserList(aFilename string)
- func UserUpdate(aUser, aFilename string)
- type IPersistence
- type TAppArgs
- type TDBpersistence
- func (dbp TDBpersistence) Count() int
- func (dbp TDBpersistence) Create(aPost *TPosting) (int, error)
- func (dbp TDBpersistence) Delete(aID uint64) error
- func (dbp TDBpersistence) Exists(aID uint64) bool
- func (dbp TDBpersistence) PathFileName(aID uint64) string
- func (dbp TDBpersistence) Read(aID uint64) (*TPosting, error)
- func (dbp TDBpersistence) Rename(aOldID, aNewID uint64) error
- func (dbp TDBpersistence) Search(aText string, aOffset, aLimit uint) (*TPostList, error)
- func (dbp TDBpersistence) Update(aPost *TPosting) (int, error)
- func (dbp TDBpersistence) Walk(aWalkFunc TWalkFunc) error
- type TFSpersistence
- func (fsp TFSpersistence) Count() int
- func (fsp TFSpersistence) Create(aPost *TPosting) (int, error)
- func (fsp TFSpersistence) Delete(aID uint64) error
- func (fsp TFSpersistence) Exists(aID uint64) bool
- func (fsp TFSpersistence) PathFileName(aID uint64) string
- func (fsp TFSpersistence) Read(aID uint64) (*TPosting, error)
- func (fsp TFSpersistence) Rename(aOldID, aNewID uint64) error
- func (fsp TFSpersistence) Search(aText string, aOffset, aLimit uint) (*TPostList, error)
- func (fsp TFSpersistence) Update(aPost *TPosting) (int, error)
- func (fsp TFSpersistence) Walk(aWalkFunc TWalkFunc) error
- type TPageHandler
- type TPostList
- func (pl *TPostList) Add(aPosting *TPosting) *TPostList
- func (pl *TPostList) Day() *TPostList
- func (pl *TPostList) Delete(aPosting *TPosting) (*TPostList, bool)
- func (pl *TPostList) IsSorted() bool
- func (pl *TPostList) Len() int
- func (pl *TPostList) Month(aYear int, aMonth time.Month) *TPostList
- func (pl *TPostList) Newest(aLimit, aOffset int) error
- func (pl *TPostList) Sort() *TPostList
- func (pl *TPostList) String() (rStr string)
- func (pl *TPostList) Week(aYear int, aMonth time.Month, aDay int) *TPostList
- type TPosting
- func (p *TPosting) After(aID uint64) bool
- func (p *TPosting) Before(aID uint64) bool
- func (p *TPosting) ChangeID(aID uint64) error
- func (p *TPosting) Clear() *TPosting
- func (p *TPosting) Date() string
- func (p *TPosting) Delete() error
- func (p *TPosting) Equal(aID uint64) bool
- func (p *TPosting) Exists() bool
- func (p *TPosting) ID() uint64
- func (p *TPosting) IDstr() string
- func (p *TPosting) LastModified() string
- func (p *TPosting) Len() int
- func (p *TPosting) Load() error
- func (p *TPosting) Markdown() []byte
- func (p *TPosting) PathFileName() string
- func (p *TPosting) Post() template.HTML
- func (p *TPosting) Set(aMarkdown []byte) *TPosting
- func (p *TPosting) Store() (int, error)
- func (p *TPosting) String() string
- func (p *TPosting) Time() time.Time
- type TView
- type TViewList
- type TWalkFunc
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
var ( // `ErrEmptyPosting` is returned when a `nil` posting is passed to // a method. ErrEmptyPosting = errors.New("empty post") // `ErrSkipAll` can be used by a `TWalkFunc` to skip the [Walk]. ErrSkipAll = errors.New("signal skipping the remaining directory walk") )
Functions ¶
func AddConsolePost ¶
AddConsolePost reads data from `StdIn` and saves it as a new posting, returning the number of bytes written and a possible I/O error.
func AddFilePost ¶
AddFilePost reads `aFilename` and adds it as a new posting, returning the number of bytes written and a possible I/O error.
`aFilename` The text file to add as a new posting.
func AddTagID ¶
`AddTagID()` checks a newly added `aPosting` for #hashtags and @mentions.
Parameters:
- `aList`: The hashlist to use (update).
- `aPosting`: The new posting to handle.
func CreateScreenshot ¶ added in v0.18.0
func CreateScreenshot(aURL string)
`CreateScreenshot()` generates a screenshot of `aURL` in background.
Parameters:
- `aURL`: The URL for which to create a screenshot image.
func InitConfig ¶
func InitConfig()
`InitConfig()` reads both the INI values and the commandline arguments.
The steps here are:
(1) read the INI file(s):
(a) read the local `./.nele.ini`, (b) read the global `/etc/nele.ini`, (c) read the user-local `~/.nele.ini`, (d) read the user-local `~/.config/nele.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 InitHashlist ¶
`InitHashlist()` initialises the hash list.
Parameters:
- `aList`: The list of #hashtags/@mentions to update.
func MDtoHTML ¶
`MDtoHTML()` converts the `aMarkdown` data and returns HTML data.
Parameters:
- `aMarkdown` The raw Markdown text to convert.
Returns:
- `[]byte`: The generated HTML data.
func MarkupCloud ¶
`MarkupCloud()` returns a list with the markup of all existing #hashtags/@mentions.
Parameters:
`aList`: The list of #hashtags/@mentions to use.
func MarkupTags ¶
`MarkupTags()` returns `aPage` with all #hashtags/@mentions marked up as a HREF links.
Parameters:
- `aPage`: The HTML page to process.
func PostingBaseDirectory ¶
func PostingBaseDirectory() string
`PostingBaseDirectory()` returns the base directory used for storing the postings.
Returns:
- `string`: The base directory tu use.
func PrepareLinkScreenshots ¶ added in v0.18.0
func PrepareLinkScreenshots(aPosting *TPosting)
`PrepareLinkScreenshots()` updates the external link(s) in `aPosting` to include page screenshot image(s) (if available).
Parameters:
- `aPosting`: The posting the text of which is going to be processed.
func ReadHashlist ¶ added in v0.9.0
`ReadHashlist()` reads all postings to (re-)build the list of #hashtags/@mentions disregarding any pre-existing list.
Parameters:
- `aList`: The list of #hashtags/@mentions to build.
func RemoveIDTags ¶
`RemoveIDTags()` removes `aID` from `aList's` items.
Parameters:
- `aList`: The hashlist to update.
- `aID`: The ID of the posting to remove.
func RemovePageScreenshots ¶ added in v0.18.0
func RemovePageScreenshots(aPosting *TPosting)
`RemovePageScreenshots()` deletes the images used in `aPosting`.
Parameters:
- `aPosting`: The posting the image(s) of which are going to be deleted.
func RenameIDTags ¶
`RenameIDTags()` renames all references of `aOldID` to `aNewID`.
Parameters:
- `aList`: The hashlist to update.
- `aOldID`: The posting's old ID.
- `aNewID`: The posting's new ID.
func ReplaceTag ¶
`ReplaceTag()` replaces the #tags/@mentions in `aList`.
Parameters:
- `aList`: The hashlist to update.
- `aSearchTag`: The old #tag/@mention to find.
- `aReplaceTag`: The new #tag/@mention to use.
func SetPersistence ¶ added in v0.20.0
func SetPersistence(aPersistence IPersistence)
`SetPersistence()` sets the persistence layer to actually use.
Parameters:
- `aPersistence`: The persistence layer to use for storing/retrieving postings.
func SetPostingBaseDirectory ¶
`SetPostingBaseDirectory()` sets the base directory used for storing the postings.
Parameters:
- `aBaseDir` The base directory to use for storing articles/postings.
Returns:
- `error`: Any error that might have occurred.
Example:
// Set the base directory to "/path/to/new/base/directory" err := nele.SetPostingBaseDirectory("/path/to/new/base/directory") if err != nil { log.Fatal(err) } // Get the current base directory fmt.Println(nele.PostingBaseDirectory()) // Set the base directory back to the default value err = nele.SetPostingBaseDirectory("./postings") if err != nil { log.Fatal(err) }
func URLparts ¶
`URLparts()` returns three parts: the base-directory of `aURL`, the remaining part of `aURL`, and a possible posting ID.
Depending on the actual value of `aURL` all return values may be empty or all may be filled; none of the first two will hold a leading slash.
Parameters:
- `aURL`: The URL as specified by a HTTP request.
Returns:
- `rPath`: The base-directory of `aURL`.
- `rTail`: The remaining part of `aURL`.
- `rID`: A user ID (if art of the URL).
func UpdateScreenshots ¶ added in v0.18.0
func UpdateScreenshots()
`UpdateScreenshots()` starts the process to update the screenshot images in all postings.
func UpdateTags ¶
`UpdateTags()` updates the #hashtag/@mention references of `aPosting`.
Parameters:
- `aList`: The hashlist to update.
- `aPosting`: The new posting to process.
func UserAdd ¶ added in v0.17.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` The name of the password file to use.
func UserCheck ¶ added in v0.17.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` The name of the password file to use.
func UserDelete ¶ added in v0.17.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` The name of the password file to use.
func UserList ¶ added in v0.17.0
func UserList(aFilename string)
UserList 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` The name of the password file to use.
func UserUpdate ¶ added in v0.17.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` The name of the password file to use.
Types ¶
type IPersistence ¶ added in v0.20.0
type IPersistence interface { // // `Create()` creates a new persistent posting. // // If the provided `aPost` is `nil`, an `ErrEmptyPosting` error // is returned. // // Parameters: // - `aPost`: The `TPosting` instance containing the article's data. // // Returns: // - `int`: The number of bytes stored. // - 'error`: A possible error, or `nil` on success. Create(aPost *TPosting) (int, error) // // `Delete()` removes the posting/article from the persistence layer // and returns a possible I/O error. // // Parameters: // - `aID`: The unique identifier of the posting to delete. // // Returns: // - 'error`: A possible error, or `nil` on success. Read(aID uint64) (*TPosting, error) // // `Update()` updates the article's data in the persistence layer. // // It returns the number of bytes written and a possible I/O error. // // If the provided `aPost` is `nil`, an `ErrEmptyPosting` error // is returned. // // Parameters: // - `aPost`: A `TPosting` instance containing the article's data. // // Returns: // - `int`: The number of bytes written. // - 'error`:` A possible error, or `nil` on success. Update(aPost *TPosting) (int, error) // // `Delete()` removes the posting/article from the persistence layer. // // Parameters: // - `aID`: The unique identifier of the posting to delete. // // Returns: // - 'error`: A possible error, or `nil` on success. Delete(aID uint64) error // // `Count()` returns the number of postings available. // // Returns: // - `int`: The number of available postings, or `0` // in case of errors. Count() int // // `Exists()` checks if a post with the given ID exists in the // persistence layer. // // Parameters: // // - `aID`: The unique identifier of the posting to check. // // Returns: // // - `bool`: `true` if the post exists, `false` otherwise. Exists(aID uint64) bool // // `PathFileName()` returns the posting's complete path-/filename. // // NOTE: The actual definition of the path-/filename depends on // the implementation of this interface. In a file-based persistence // layer it would be a `/path/directory/filename` string. // However, in a database-based persistence layer it would be the // `/path/file` of the database file. // // Parameters: // - `aID`: The unique identifier of the posting to handle. // // Returns: // - `string`: The path-/filename associated with `aID`. PathFileName(aID uint64) string // // `Rename()` renames a posting from its old ID to a new ID. // // Parameters: // - aOldID: The unique identifier of the posting to be renamed. // - aNewID: The new unique identifier for the new posting. // // Returns: // - `error`: An error if the operation fails, or `nil` on success. Rename(aOldID, aNewID uint64) error // // `Search()` retrieves a list of postings based on a search term. // // A zero value of `aLimit` means: no limit alt all. // // The returned `TPostList` type is a slice of `TPosting` instances, // where `TPosting` is a struct representing a single posting. If // the returned slice is an empty list then no matching postings were // found; if it is `nil` it means there was an error retrieving the // matches. // // Parameters: // - `aText`: The search term to look for. // - `aOffset`: An offset in the result set of the search results. // - `aLimit`: The maximum number of search results to return. // // Returns: // - `*TPostList`: The list of search results, or `nil` in case of errors. // - `error`: If the search operation fails, or `nil` on success. Search(aText string, aOffset, aLimit uint) (*TPostList, error) // // `Walk()` visits all existing postings, calling `aWalkFunc` // for each posting. // // Parameters: // - `aWalkFunc`: The function to call for each posting. // // Returns: // - `error`: a possible error occurring the traversal process. Walk(aWalkFunc TWalkFunc) error }
`IPersistence` defines a persistence layer for storing `TPosting` objects. It uses a CRUD interface with some additional methods as documented below.
func Persistence ¶ added in v0.20.0
func Persistence() IPersistence
`Persistence()` returns the persistence layer to actually use creating, updating, deleting, searching, and walking through postings.
Returns:
- `IPersistence`: The persistence layer to use for storing/retrieving postings.
type TAppArgs ¶ added in v0.17.0
type TAppArgs struct { AccessLog string // (optional) name of page access logfile Addr string // listen address ("1.2.3.4:5678") BlogName string // name/description of this blog CertKey string // TLS certificate key CertPem string // private TLS certificate DataDir string // base directory of application's data Dump bool // Debug: dump this structure to `StdOut` ErrorLog string // (optional) name of page error logfile GZip bool // send compressed data to remote browser HashFile string // file of hashtag/mention database // Intl string // path/filename of the localisation file Lang string // default GUI language LogStack bool // log stack trace in case of errors MaxFileSize int64 // max. upload file size Name string // name of the actual program PageLength uint // the number of postings to show per page PostAdd bool // whether to write a posting from commandline PostFile string // name of file to post Realm string // host/domain to secure by BasicAuth Screenshot bool // whether to use page screenshots or not 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 UserFile string // (optional) name of page access logfile UserList bool // print out a list of current users UserUpdate string // username to update in password list // contains filtered or unexported fields }
`TAppArgs` is a collection of commandline arguments and INI values.
var ( // `AppArgs` holds the commandline arguments and INI values combined. // // This structure should be considered `R/O` after it was set up // by a call to `InitConfig()`. AppArgs TAppArgs )
func (TAppArgs) String ¶ added in v0.17.0
`String()` implements the `Stringer` interface returning a (pretty printed) string representation of the current `TAppArgs` instance.
NOTE: This method is meant mostly for debugging purposes.
Returns:
- `string`: The string representation of the current app configuration.
type TDBpersistence ¶ added in v0.20.0
type TDBpersistence struct {
// contains filtered or unexported fields
}
`TDBpersistence` is a database-based `IPersistence` implementation.
func NewDBpersistence ¶ added in v0.20.0
func NewDBpersistence(aName string) *TDBpersistence
`NewDBpersistence()` creates a new instance of `TDBpersistence`.
In case of errors initialising the database connection, the function returns a `nil` value.
Parameters:
- `aName`: The name of the database file to use.
Returns:
- `*TDBpersistence`: A persistence instance instance.
func (TDBpersistence) Count ¶ added in v0.20.0
func (dbp TDBpersistence) Count() int
`Count()` returns the number of postings currently available.
NOTE: This method is very resource intensive as it has to count all the posts stored in the filesystem.
Returns:
- `int`: The number of available postings, or `0` in case of errors.
func (TDBpersistence) Create ¶ added in v0.20.0
func (dbp TDBpersistence) Create(aPost *TPosting) (int, error)
`Create()` creates a new posting in the filesystem.
If the provided `aPost` is `nil`, an `ErrEmptyPosting` error is returned.
Parameters:
- `aPost`: The `TPosting` instance containing the article's data.
Returns:
- `int`: The number of bytes stored.
- 'error`:` A possible error, or `nil` on success.
func (TDBpersistence) Delete ¶ added in v0.20.0
func (dbp TDBpersistence) Delete(aID uint64) error
`Delete()` removes the posting/article from the filesystem and returns a possible I/O error.
Parameters:
- `aID`: The unique identifier of the posting to delete.
Returns:
- 'error`: A possible I/O error, or `nil` on success.
Side Effects:
- Invalidates the internal count cache.
func (TDBpersistence) Exists ¶ added in v0.20.0
func (dbp TDBpersistence) Exists(aID uint64) bool
`Exists()` checks if a file with the given ID exists in the filesystem.
It returns a boolean value indicating whether the file exists.
Parameters:
- `aID`: The unique identifier of the posting to check.
Returns:
- `bool`: `true` if the file exists, `false` otherwise.
func (TDBpersistence) PathFileName ¶ added in v0.20.0
func (dbp TDBpersistence) PathFileName(aID uint64) string
`PathFileName()` returns the posting's complete path-/filename.
The returned path-/filename is in the format:
<base_directory>/<posting_id>.md
Parameters:
- `aID`: The unique identifier of the posting to handle.
Returns:
- `*string`: The path-/filename associated with `aID`.
func (TDBpersistence) Read ¶ added in v0.20.0
func (dbp TDBpersistence) Read(aID uint64) (*TPosting, error)
`Read()` reads the posting from disk, returning a possible I/O error.
Parameters:
- `aID`: The unique identifier of the posting to be read.
Returns:
- `*TPosting`: The `TPosting` instance containing the article's data, or `nil` if the record doesn't exist.
- 'error`: A possible I/O error, or `nil` on success.
func (TDBpersistence) Rename ¶ added in v0.20.0
func (dbp TDBpersistence) Rename(aOldID, aNewID uint64) error
`Rename()` renames a posting from its old ID to a new ID.
Parameters:
- aOldID: The unique identifier of the posting to be renamed.
- aNewID: The new unique identifier for the new posting.
Returns:
- `error`: An error if the operation fails, or `nil` on success.
func (TDBpersistence) Search ¶ added in v0.20.0
func (dbp TDBpersistence) Search(aText string, aOffset, aLimit uint) (*TPostList, error)
`Search()` retrieves a list of postings based on a search term.
The method uses SQLite's FTS5 (Full-Text Search) feature to perform the search. If the underlying database does not support FTS5, the method falls back to a LIKE-based search.
A zero value of `aLimit` means: no limit alt all.
The returned `TPostList` type is a slice of `TPosting` instances, where `TPosting` is a struct representing a single posting. If the returned slice is an empty list then no matching postings were found; if it is `nil` it means there was an error retrieving the matches.
Parameters:
- `aText`: The search query string.
- `aOffset`: An offset in the database result set of the search results.
- `aLimit`: The maximum number of search results to return.
Returns:
- `*TPostList`: The list of search results, or `nil` in case of errors.
- `error`: If the search operation fails, or `nil` on success.
func (TDBpersistence) Update ¶ added in v0.20.0
func (dbp TDBpersistence) Update(aPost *TPosting) (int, error)
`Update()` updates the article's Markdown in the database.
It returns the number of bytes stored and a possible I/O error.
If the provided `aPost` is `nil`, an `ErrEmptyPosting` error is returned.
Parameters:
- `aPost`: A `TPosting` instance containing the article's data.
Returns:
- `int`: The number of bytes written to the file.
- 'error`:` A possible I/O error, or `nil` on success.
Side Effects:
- Invalidates the internal count cache.
func (TDBpersistence) Walk ¶ added in v0.20.0
func (dbp TDBpersistence) Walk(aWalkFunc TWalkFunc) error
`Walk()` visits all existing postings, calling `aWalkFunc` for each posting.
Parameters:
- `aWalkFunc`: The function to call for each posting.
Returns:
- `error`: a possible error occurring the traversal process.
type TFSpersistence ¶ added in v0.20.0
type TFSpersistence struct {
// contains filtered or unexported fields
}
`TFSpersistence` is a file-based `IPersistence` implementation.
func NewFSpersistence ¶ added in v0.20.0
func NewFSpersistence() *TFSpersistence
`NewFSpersistence()` creates a new instance of `TFSpersistence`.
It does not take any parameters.
Returns:
- `*TFSpersistence`: A persistence instance instance.
func (TFSpersistence) Count ¶ added in v0.20.0
func (fsp TFSpersistence) Count() int
`Count()` returns the number of postings currently available.
NOTE: This method is very resource intensive as it has to count all the posts stored in the filesystem.
Returns:
- `int32`: The number of available postings, or `0` in case of I/O errors.
Side Effects:
- Updates the count cache.
func (TFSpersistence) Create ¶ added in v0.20.0
func (fsp TFSpersistence) Create(aPost *TPosting) (int, error)
`Create()` creates a new posting in the filesystem.
If the provided `aPost` is `nil`, an `ErrEmptyPosting` error is returned.
Parameters:
- `aPost`: The `TPosting` instance containing the article's data.
Returns:
- `int`: The number of bytes written to the file.
- 'error`:` A possible error, or `nil` on success.
Side Effects:
- Invalidates the internal count cache.
func (TFSpersistence) Delete ¶ added in v0.20.0
func (fsp TFSpersistence) Delete(aID uint64) error
`Delete()` removes the posting/article from the filesystem and returns a possible I/O error.
Parameters:
- `aID`: The unique identifier of the posting to delete.
Returns:
- 'error`: A possible I/O error, or `nil` on success.
Side Effects:
- Invalidates the internal count cache.
func (TFSpersistence) Exists ¶ added in v0.20.0
func (fsp TFSpersistence) Exists(aID uint64) bool
`Exists()` checks if a file with the given ID exists in the filesystem.
It returns a boolean value indicating whether the file exists.
Parameters:
- `aID`: The unique identifier of the posting to check.
Returns:
- `bool`: `true` if the file exists, `false` otherwise.
func (TFSpersistence) PathFileName ¶ added in v0.20.0
func (fsp TFSpersistence) PathFileName(aID uint64) string
`PathFileName()` returns the posting's complete path-/filename.
The returned path-/filename is in the format:
<base_directory>/<posting_id>.md
Parameters:
- `aID`: The unique identifier of the posting to handle.
Returns:
- `*string`: The path-/filename associated with `aID`.
func (TFSpersistence) Read ¶ added in v0.20.0
func (fsp TFSpersistence) Read(aID uint64) (*TPosting, error)
`Read()` reads the posting from disk, returning a possible I/O error.
Parameters:
- `aID`: The unique identifier of the posting to be read.
Returns:
- `*TPosting`: The `TPosting` instance containing the article's data, or `nil` if the file does not exist.
- 'error`: A possible I/O error, or `nil` on success.
func (TFSpersistence) Rename ¶ added in v0.20.0
func (fsp TFSpersistence) Rename(aOldID, aNewID uint64) error
`Rename()` renames a posting from its old ID to a new ID.
Parameters:
- aOldID: The unique identifier of the posting to be renamed.
- aNewID: The new unique identifier for the new posting.
Returns:
- `error`: An error if the operation fails, or `nil` on success.
func (TFSpersistence) Search ¶ added in v0.20.0
func (fsp TFSpersistence) Search(aText string, aOffset, aLimit uint) (*TPostList, error)
`Search()` retrieves a list of postings based on a search term.
A zero value of `aLimit` means: no limit alt all.
The returned `TPostList` type is a slice of `TPosting` instances, where `TPosting` is a struct representing a single posting. If the returned slice is an empty list then no matching postings were found; if it is `nil` it means there was an error retrieving the matches.
Parameters:
- `aText`: The search query string.
- `aOffset`: An offset in the database result set of the search results.
- `aLimit`: The maximum number of search results to return.
Returns:
- `*TPostList`: The list of search results, or `nil` in case of errors.
- `error`: If the search operation fails, or `nil` on success.
func (TFSpersistence) Update ¶ added in v0.20.0
func (fsp TFSpersistence) Update(aPost *TPosting) (int, error)
`Update()` updates the article's Markdown on disk.
It returns the number of bytes written to the file and a possible I/O error.
If the provided `aPost` is `nil`, an `ErrEmptyPosting` error is returned.
Parameters: - `aPost`: A `TPosting` instance containing the article's data.
Returns: - `int`: The number of bytes written to the file. - 'error`:` A possible I/O error, or `nil` on success.
Side Effects: - Invalidates the internal count cache.
func (TFSpersistence) Walk ¶ added in v0.20.0
func (fsp TFSpersistence) Walk(aWalkFunc TWalkFunc) error
`Walk()` visits all existing postings, calling `aWalkFunc` for each posting.
Parameters:
- `aWalkFunc`: The function to call for each posting.
Returns:
- `error`: a possible error occurring the traversal process.
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()` creates a new `TPageHandler` instance.
The returned object implements the `errorhandler.TErrorPager`, `http.Handler`, and `passlist.TAuthDecider` interfaces.
Returns:
- `*TPageHandler`: The handler for HTTP request/response.
- `error`: A possible processing error.
func (*TPageHandler) GetErrorPage ¶
func (ph *TPageHandler) GetErrorPage(aData []byte, aStatus int) []byte
`GetErrorPage()` returns an error page for `aStatus`, implementing the `TErrorPager` interface.
Parameters:
- `aData`: An error page to use.
- `aStatus`: The HTTP status to handle.
Returns:
- `[]byte`: The complete error page to send to the remote caller.
func (*TPageHandler) Len ¶
func (ph *TPageHandler) Len() int
`Len()` returns the length of the internal views list.
Returns:
- `int`: The number of available views/pages.
func (*TPageHandler) NeedAuthentication ¶
func (ph *TPageHandler) NeedAuthentication(aRequest *http.Request) bool
`NeedAuthentication()` returns `true` if authentication is needed, or `false` otherwise.
Parameters:
- `aRequest`: The request to check.
Returns:
- `bool`: Whether or not to require authentication.
func (*TPageHandler) ServeHTTP ¶
func (ph *TPageHandler) ServeHTTP(aWriter http.ResponseWriter, aRequest *http.Request)
`ServeHTTP()` handles the incoming HTTP requests.
type TPostList ¶
type TPostList []TPosting
`TPostList` is a list of postings to be injected into a template/view.
func NewPostList ¶
func NewPostList() *TPostList
NewPostList returns a new (empty) TPostList instance.
func SearchPostings ¶
`SearchPostings()` traverses all postings looking for `aText` in the respective post's text.
The returned `TPostList` can be empty because (a) `aText` could not be compiled into a regular expression, (b) no files to search were found, or (c) no files matched `aText`.
Parameters:
- `aText`: The text to look for in the postings.
Returns:
- `*TPostList`: The found list.
func (*TPostList) Add ¶
`Add()` appends `aPosting` to the list.
Parameters:
- `aPosting` contains the actual posting's text.
Returns:
- `*TPostList`: The updated list.
func (*TPostList) Day ¶
`Day()` adds all postings of the current day to the list.
Returns:
- `*TPostList`: A list with the postings of the current day.
func (*TPostList) Delete ¶
`Delete()` removes `aPosting` from the list, returning the (possibly modified) list and whether the operation war successful.
Parameters:
- `aPosting`: The posting to remove from this list.
Returns:
- `*TPostList`: The updated list.
- `bool`: Whether `aPosting` was successfully removed.
func (*TPostList) IsSorted ¶
`IsSorted()` returns whether the list is sorted (in descending order).
Returns:
- `bool`: `true` if the list is sorted in descending order.
func (*TPostList) Len ¶
`Len()` returns the number of postings stored in this list.
Returns:
`int`: The number of postings in the current list.
func (*TPostList) Month ¶
`Month()` adds all postings of `aMonth` to the list.
Parameters:
- `aYear`: The year to lookup; if zero the current year is used.
- `aMonth`: The year's month to lookup; if zero the current month is used.
Returns:
- `*TPostList`: A list with the postings of the given year and month.
func (*TPostList) Newest ¶
`Newest()` adds the last `aLimit` of postings to the list.
The resulting list is sorted in descending order (newest first) with at most `aLimit` posts.
Parameters:
- `aLimit`: The number of articles to show.
- `aOffset`: The start number to use.
Returns:
- `error`: A possible error during processing of the request.
func (*TPostList) Sort ¶
`Sort()` returns the list sorted by posting IDs (i.e. date/time) in descending order.
Returns:
- `*TPostList`: The current list of postings in descending order.
func (*TPostList) String ¶ added in v0.20.0
`String()` returns a stringified version of the postlist instance.
Note: This is mainly for debugging purposes and has no real life use.
Returns:
- `string`: The stringified version of the current postlist.
func (*TPostList) Week ¶
`Week()` adds all postings of the current week to the list.
Parameters:
- `aYear` The year to lookup; if zero the current year is used.
- `aMonth` The year's month to lookup; if zero the current month is used.
- `aDay` The month's day to lookup; if zero the current day is used.
Returns:
- `*TPostList`: A list with the postings of the given year, month, and day.
type TPosting ¶
type TPosting struct {
// contains filtered or unexported fields
}
`TPosting` is a single article/posting..
func NewPosting ¶
`NewPosting()` returns a new posting structure with the given article text.
If `aID` is zero, the current time is used to generate a unique ID.
Parameters:
- `aID`: A uint64 representing the unique identifier of the posting.
- `aText`: A string containing the initial Markdown text of the article.
Returns:
- `*TPosting`: A new `TPosting` instance.
func (*TPosting) After ¶
`After()` reports whether this posting is younger than the one identified by `aID`.
Parameters:
- `aID`: The ID of another posting to compare.
Returns:
- `bool`: Whether the current posting is older than `aID`.
func (*TPosting) Before ¶
`Before()` reports whether this posting is older than the one identified by `aID`.
Parameters:
- `aID`: The ID of another posting to compare.
Returns:
- `bool`: Whether the current posting is younger than `aID`.
func (*TPosting) ChangeID ¶ added in v0.20.0
`ChangeID()` changes the ID of the current posting including the persistence layer.
Note: This method is provided for rare cases when a posting's ID has to be changed.
Parameters:
- `aID`: is the ID of another posting to compare.
Returns:
- `error`: A possible error during processing the request.
func (*TPosting) Clear ¶
`Clear()` resets the text field to its zero value.
This method does NOT remove the file (if any) associated with this posting/article; for that call the `Delete()` method.
Returns:
- `*TPosting`: The current posting without any text.
func (*TPosting) Date ¶
`Date()` returns the posting's date as a formatted string (`yyyy-mm-dd`).
Returns:
- `string`: The posting's creation date in string format.
func (*TPosting) Delete ¶
`Delete()` removes the posting/article from the persistence layer returning a possible I/O error.
This method does NOT empty the markdown text of the object; for that call the `[Clear]` method.
Returns:
- `error`: A possible error during processing the request.
func (*TPosting) Equal ¶
`Equal()` reports whether this posting is of the same time as `aID`.
Parameters:
- `aID`: The ID of the posting to compare with this one.
Returns:
- `bool`: `true` if the posting is of the same as `aID`.
func (*TPosting) Exists ¶
`Exists()` returns whether there is a file with more than zero bytes.
Returns:
- `bool`: `true` if the posting exists in the persistence layer.
func (*TPosting) ID ¶
`ID()` returns the article's identifier.
Returns:
- `uint64`: The posting's unique ID.
func (*TPosting) IDstr ¶ added in v0.20.0
`IDstr()` returns the article's identifier in string format.
The identifier is based on the article's creation time and given in hexadecimal notation.
This method allows the template to validate and use the placeholder `.ID`
Returns:
- `string`: The article's identifier in string format.
func (*TPosting) LastModified ¶ added in v0.17.5
`LastModified()` returns the last-modified date/time of the posting.
The format of the returned string would be like "Mon, 02 Jan 2006 15:04:05 MST"
Returns:
- `string`: The article's last modified date.
func (*TPosting) Len ¶
`Len()` returns the current length of the posting's Markdown text.
If the markup is not already in memory this method calls `[Load]` to read the text data from the persistence layer.
Returns:
- `int`: The current length of the posting's text.
func (*TPosting) Load ¶
`Load()` reads the Markdown from disk, returning a possible I/O error.
Returns:
- `error`: A possible error during processing the request.
func (*TPosting) Markdown ¶
`Markdown()` returns the Markdown of this article.
If the markdown is not already in memory this methods calls `[Load]` to read the text data from the persistence layer.
Returns:
- `[]byte`: The current posting's text.
func (*TPosting) PathFileName ¶
`PathFileName()` returns the article's complete path-/filename.
NOTE: The actual definition of the path-/filename depends on the implementation of this interface. In a file-based persistence layer it would be a `/path/directory/filename` string. However, in a database-based persistence layer it would be the `/path/file` of the database file.
Returns:
- `string`: The current posting's path-/filename.
func (*TPosting) Post ¶
`Post()` returns the article's HTML markup.
This method uses the `Markdown()` method to get the latest version of the article's Markdown text. It then converts this text to HTML using the `MDtoHTML()` function and wraps it with the necessary HTML tags using the `MarkupTags()` function.
The resulting HTML is returned as a `template.HTML` value.
Returns:
- `template.HTML`: The HTML markup of the current posting's text.
func (*TPosting) Set ¶
`Set()` assigns the article's Markdown text.
Parameters:
- `aMarkdown`: The actual Markdown text to assign.
Returns:
- `*TPosting`: The updated posting.
func (*TPosting) Store ¶
`Store()` writes the article's Markdown to disk returning the number of bytes written and a possible I/O error.
The actual storing is delegated to the persistence layer.
Returns:
- `int`: The number of bytes written.
- 'error`: A possible error, or `nil` on success.
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`.
`aName` serves as both the main template's name as well as the view's name; it's given here without the filename extension (i.e. w/o `.gohtml`).
Parameters:
- `aName`: The name of the template file providing the page's main body.
Returns:
- `*TView`: A new `TView` instance.
- `error`: A possible error during processing.
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.
If an error occurs executing the template or writing its output, execution stops, and the method returns without writing anything to the output `aWriter`.
Parameters:
- `aWriter`: A `http.ResponseWriter` to handle the executed template.
- `aData`: A list of data to be injected into the template.
Returns:
- `error`: A possible error during processing.
func (*TView) RenderedPage ¶
func (v *TView) RenderedPage(aData *TemplateData) ([]byte, error)
`RenderedPage()` returns the rendered template/page and a possible Error executing the template.
Parameters: `aData` is a list of data to be injected into the template.
Returns:
- `error`: A possible error during processing.
type TViewList ¶
`TViewList` is a list of `TView` instances (to be used as a template pool). It's a map indexed by a name pointing to a view instance.
func NewViewList ¶
`NewViewList()` creates a new `TViewList` instance with all available views.
Returns:
- `*TViewList`: A new `TViewList` instance.
- `error`: A possible error during processing.
func (*TViewList) Get ¶
`Get()` returns the view with `aName`.
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.
Parameters:
- `aName`: The name of the `TView` instance to retrieve.
Returns:
- `*TView`: The `TView` instance.
- `bool`: `true` if `aName` exists in the list, or `false` otherwise.
func (*TViewList) Len ¶ added in v0.20.0
`Len()` returns the number of views in the `TViewList`.
This method implements the `Len()` function from the sort.Interface interface, which is used for sorting TViewList instances.
Returns:
- `int`: The number of views in the TViewList.
func (*TViewList) Render ¶
func (vl *TViewList) Render(aName string, aWriter http.ResponseWriter, aData *TemplateData) error
`Render()` executes the template identified by `aName`.
If an error occurs executing the template or writing its output, execution stops, and the method returns without writing anything to the output `aWriter`.
Parameters:
- `aName`: The name of the template/view to use.
- `aWriter`: A `http.ResponseWriter` to handle the executed template.
- `aData`: A list of data to be injected into the template.
Returns:
- `error`: A possible error during processing.
func (*TViewList) RenderedPage ¶
func (vl *TViewList) RenderedPage(aName string, aData *TemplateData) ([]byte, error)
`RenderedPage()` returns the rendered template/page with the key `aName`.
Parameters:
- `aName`: The name of the template/view to use.
- `aData`: A list of data to be injected into the template.
Returns:
- `error`: A possible error during processing.
type TWalkFunc ¶ added in v0.20.0
This function type is used by `Walk()`.
Parameters:
- `aID`: The ID of the posting to handle.
type TemplateData ¶ added in v0.11.1
`TemplateData` is a list of values to be injected into a template.
func NewTemplateData ¶ added in v0.11.1
func NewTemplateData() *TemplateData
`NewTemplateData()` returns a new (empty) `TemplateData` instance.
Returns:
- `*TemplateData`: The new data list.
func (TemplateData) Get ¶ added in v0.17.2
func (dl TemplateData) Get(aKey string) (rValue any, rOK bool)
`Get()` returns the value associated with `aKey` and `true`.
If `aKey` is not present in the list then the `bool` return value will be `false`.
Parameters:
- `aKey`: The value's identifier (as used as placeholder in the template).
Returns:
- `any`: The value associated with `aKey`.
- `bool`: Indicator whether `aKey` was found.
func (*TemplateData) Set ¶ added in v0.11.1
func (dl *TemplateData) Set(aKey string, aValue any) *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`.
Parameters:
- `aKey`: The value's identifier (as used as placeholder in the template).
- `aValue`: The data entry's value.
Returns:
- `*TemplateData`: The updated data list.