Documentation
¶
Overview ¶
Package nele implements a simple blog-server.
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 ¶
- Variables
- func AddConsolePost() (int64, error)
- func AddFilePost(aFilename string) (int64, error)
- func AddTagID(aList *hashtags.THashList, aPosting *TPosting)
- func AddUser(aUser, aFilename string)
- func CheckUser(aUser, aFilename string)
- func DeleteUser(aUser, aFilename string)
- func InitConfig()
- func InitHashlist(aList *hashtags.THashList)
- func ListUsers(aFilename string)
- func MDtoHTML(aMarkdown []byte) []byte
- func MarkupCloud(aList *hashtags.THashList) []template.HTML
- func MarkupTags(aPage []byte) []byte
- func NewID() string
- func PostingBaseDirectory() string
- func PrepareLinkPreviews(aPosting *TPosting, aImageURLdir string)
- func RemoveIDTags(aList *hashtags.THashList, aID string)
- func RemovePagePreviews(aPosting *TPosting)
- func RemoveWhiteSpace(aPage []byte) []byte
- func RenameIDTags(aList *hashtags.THashList, aOldID, aNewID string)
- func ReplaceTag(aList *hashtags.THashList, aSearchTag, aReplaceTag string)
- func SetPostingBaseDirectory(aBaseDir string)
- func ShowHelp()
- func URLparts(aURL string) (rDir, rPath string)
- func UpdatePreviews(aPostingBaseDir, aImgURLdir string)
- func UpdateTags(aList *hashtags.THashList, aPosting *TPosting)
- func UpdateUser(aUser, aFilename string)
- type TDataList
- type TPageHandler
- func (ph *TPageHandler) Address() string
- func (ph *TPageHandler) GetErrorPage(aData []byte, aStatus int) []byte
- func (ph *TPageHandler) Len() int
- func (ph *TPageHandler) NeedAuthentication(aRequest *http.Request) bool
- func (ph *TPageHandler) ServeHTTP(aWriter http.ResponseWriter, aRequest *http.Request)
- type TPostList
- func (pl *TPostList) Add(aPosting *TPosting) *TPostList
- func (pl *TPostList) Article(aID string) *TPostList
- func (pl *TPostList) Day() *TPostList
- func (pl *TPostList) Delete(aPosting *TPosting) (*TPostList, bool)
- func (pl *TPostList) Index(aPosting *TPosting) int
- func (pl *TPostList) IsSorted() bool
- func (pl *TPostList) Len() int
- func (pl *TPostList) Month(aYear int, aMonth time.Month) *TPostList
- func (pl *TPostList) Newest(aNumber, aStart int) error
- func (pl *TPostList) Sort() *TPostList
- func (pl *TPostList) Week(aYear int, aMonth time.Month, aDay int) *TPostList
- type TPosting
- func (p *TPosting) After(aID string) bool
- func (p *TPosting) Before(aID string) bool
- func (p *TPosting) Clear() *TPosting
- func (p *TPosting) Date() string
- func (p *TPosting) Delete() error
- func (p *TPosting) Equal(aID string) bool
- func (p *TPosting) Exists() bool
- func (p *TPosting) ID() 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() (int64, error)
- func (p *TPosting) String() string
- func (p *TPosting) Time() time.Time
- type TView
- type TViewList
Constants ¶
This section is empty.
Variables ¶
var (
// AppArguments is the list for the cmdline arguments and INI values.
AppArguments tAguments
)
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.
func AddTagID ¶ added in v0.8.0
AddTagID checks a newly added `aPosting` for #hashtags and @mentions.
`aList` The hashlist to use (update). `aPosting` The new posting to handle.
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 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.2.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: (1) read the INI file(s), (2) merge the commandline arguments the INI values into the global `AppArguments` variable.
This function is meant to be called first thing in the program's `main()`.
func InitHashlist ¶ added in v0.7.0
InitHashlist initialises the hash list.
`aList` The list of #hashtags/@mentions to update.
func ListUsers ¶ added in v0.3.0
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 MDtoHTML ¶
MDtoHTML converts the `aMarkdown` data returning HTML data.
`aMarkdown` the raw Markdown text to convert.
func MarkupCloud ¶ added in v0.7.0
MarkupCloud returns a list with the markup of all existing #hashtags/@mentions.
`aList` The list of #hashtags/@mentions to use.
func MarkupTags ¶ added in v0.7.0
MarkupTags returns `aPage` with all #hashtags/@mentions marked up as a HREF links.
`aPage` The HTML page to process.
func NewID ¶
func NewID() string
NewID returns a new article ID. It is based on the current date/time and given in hexadecimal notation. It's assumend that no more than one ID per nanosecond is required.
func PostingBaseDirectory ¶
func PostingBaseDirectory() string
PostingBaseDirectory returns the base directory used for storing articles/postings.
func PrepareLinkPreviews ¶ added in v0.8.0
PrepareLinkPreviews updates the external link(s) in `aPosting` to include page preview image(s) (if available).
`aPosting` is the posting the text of which is going to be processed. `aImageURLdir` is the URL directory for page preview images.
func RemoveIDTags ¶ added in v0.8.0
RemoveIDTags removes `aID` from `aList's` items.
`aList` The hashlist to update. `aID` The ID of the posting to remove.
func RemovePagePreviews ¶ added in v0.8.0
func RemovePagePreviews(aPosting *TPosting)
RemovePagePreviews deletes the images used in `aPosting`.
`aPosting` The posting the image(s) of which are going to be deleted.
func RemoveWhiteSpace ¶
RemoveWhiteSpace removes HTML comments and unnecessary 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 RenameIDTags ¶ added in v0.8.0
RenameIDTags renames all references of `aOldID` to `aNewID`.
`aList` The hashlist to update. `aOldID` The posting's old ID. `aNewID` The posting's new ID.
func ReplaceTag ¶ added in v0.8.0
ReplaceTag replaces the #tags/@mentions in `aList`.
`aList` The hashlist to update. `aSearchTag` The old #tag/@mention to find. `aReplaceTag` The new #tag/@mention to use.
func SetPostingBaseDirectory ¶
func SetPostingBaseDirectory(aBaseDir string)
SetPostingBaseDirectory sets the base directory used for storing articles/postings.
`aBaseDir` The base directory to use for storing articles/postings.
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 UpdatePreviews ¶ added in v0.8.0
func UpdatePreviews(aPostingBaseDir, aImgURLdir string)
UpdatePreviews starts the process to update the preview images in all postings.
`aPostingBaseDir` is the base directory used for storing
articles/postings.
`aImageURLdir` is the URL directory for page preview images.
func UpdateTags ¶ added in v0.8.0
UpdateTags updates the #hashtag/@mention references of `aPosting`.
`aList` The hashlist to update. `aPosting` The new posting to process.
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 TDataList ¶
type TDataList map[string]interface{}
TDataList is a list of values to be injected into a template.
func NewDataList ¶
func NewDataList() *TDataList
NewDataList returns a new (empty) TDataList instance.
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) Len ¶
func (ph *TPageHandler) Len() int
Len returns the length of the internal views list.
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 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 the sub-directories of `aBaseDir` looking for `aText` in all posting files.
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`.
`aText` is the text to look for in the postings.
func (*TPostList) Add ¶
Add appends `aPosting` to the list.
`aPosting` contains the actual posting's text.
func (*TPostList) Article ¶
Article adds the posting identified by `aID` to the list.
`aID` is the ID of the posting to add to this list.
func (*TPostList) Delete ¶
Delete removes `aPosting` from the list, returning the (possibly modified) list and whether the operation war successful.
`aPosting` is the posting o remove from this list.
func (*TPostList) Index ¶
Index returns the 0-based list index of `aPosting`. In case `aPosting` was not found in list the return value will be `-1`.
`aPosting` is the posting to lookup in this list.
func (*TPostList) IsSorted ¶
IsSorted returns `true` if the list is sorted (in descending order), or `false` otherwise.
func (*TPostList) Month ¶
Month adds all postings of `aMonth` to the list.
`aYear` the year to lookup; if `0` (zero) the current year
is used.
`aMonth` the year's month to lookup; if `0` (zero) the
current month is used.
func (*TPostList) Newest ¶
Newest adds the last `aNumber` of postings to the list.
The resulting list is sorted in descending order (newest first) with at most `aNumber` posts.
`aNumber` The number of articles to show. `aStart` The start number to use.
func (*TPostList) Sort ¶
Sort returns the list sorted by posting IDs (i.e. date/time) in descending order.
type TPosting ¶
type TPosting struct {
// contains filtered or unexported fields
}
TPosting is a single article/posting to be used by a template.
func NewPosting ¶
NewPosting returns a new posting structure with an empty article text.
`aID` if an empty string the `NewID()` function is called
to provide a new article ID.
func (*TPosting) After ¶
After reports whether this posting is younger than the one identified by `aID`.
`aID` is the ID of another posting to compare.
func (*TPosting) Before ¶
Before reports whether this posting is older than the one identified by `aID`.
`aID` is the ID of another posting to compare.
func (*TPosting) Clear ¶
Clear resets the internal fields to their respective zero values.
This method does NOT remove the file (if any) associated with this posting/article; for that call the `Delete()` method.
func (*TPosting) Delete ¶
Delete removes the posting/article from the filesystem returning a possible I/O error.
This method does NOT empty the markdown text of the object; for that call the `Clear()` method.
func (*TPosting) Equal ¶
Equal reports whether this posting is of the same time as `aID`.
`aID` The ID of the posting to compare with this one.
func (*TPosting) ID ¶
ID returns the article's identifier.
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`
func (*TPosting) Len ¶
Len returns the current length of the posting's Markdown text.
If the markup is not already in memory this methods calls `TPosting.Load()` to read the text data from the filesystem.
func (*TPosting) Markdown ¶
Markdown returns the Markdown of this article.
If the markup is not already in memory this methods calls `TPosting.Load()` to read the text data from the filesystem.
func (*TPosting) PathFileName ¶
PathFileName returns the article's complete path-/filename.
func (*TPosting) Set ¶
Set assigns the article's Markdown text.
`aMarkdown` is the actual Markdown text of the article to assign.
func (*TPosting) Store ¶
Store writes the article's Markdown to disk returning the number of bytes written and a possible I/O error.
The file is created on disk with mode `0640` (`-rw-r-----`).
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 *TDataList) 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`.
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 ¶
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 ¶
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.