Documentation
¶
Overview ¶
Package blog 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 AddUser(aUser, aFilename string)
- func CheckUser(aUser, aFilename string)
- func DeleteUser(aUser, aFilename string)
- func ListUser(aFilename string)
- func MDtoHTML(aMarkdown []byte) []byte
- func NewID() string
- func PostingBaseDirectory() string
- func RemoveWhiteSpace(aPage []byte) []byte
- func SetPostingBaseDirectory(aBaseDir string) (rErr error)
- func ShowHelp()
- func URLparts(aURL string) (rDir, rPath string)
- 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) IsFile() bool
- 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) 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 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 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 MDtoHTML ¶
MDtoHTML converts the `aMarkdown` data returning HTML data.
`aMarkdown` the raw Markdown text to convert.
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 needed.
func PostingBaseDirectory ¶
func PostingBaseDirectory() string
PostingBaseDirectory returns the base directory used for storing articles/postings.
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 SetPostingBaseDirectory ¶
SetPostingBaseDirectory set the base directory used for storing articles/postings.
`aBaseDir` is 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 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 view list.
func (*TPageHandler) NeedAuthentication ¶
func (ph *TPageHandler) NeedAuthentication(aRequest *http.Request) bool
NeedAuthentication returns `true` if authentication is needed, or `false` otherwise.
`aURL` is the URL 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.
`aBaseDir` is a directory storing the postings.
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) Delete ¶
Delete removes `aPosting` from the list, returning the (possibly modified) list and whether the opration war successful.
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`.
func (*TPostList) Month ¶
Month adds all postings of a month 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` postings to the list.
The resulting list is sorted in descending order (newest first) with at most `aNumber` posts.
`aNumber` is the number of articles to show.
`aStart` is the start number to use.
type TPosting ¶
type TPosting struct {
// contains filtered or unexported fields
}
TPosting is a single /article/posting to be injected into a template.
func NewPosting ¶
func NewPosting() *TPosting
NewPosting returns a new posting structure with an empty article text.
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 internal fields of the object; for that call the `Clear()` method.
func (*TPosting) Exists ¶ added in v0.0.10
Exists returns whether there is a file with more than zero bytes.
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 methods allows the template to validate and use the placeholder `.ID`
func (*TPosting) Markdown ¶
Markdown returns the Markdown of this article.
If the markup is not already in memory this methods tries to read the required data from the filesystem.
In case of I/O errors while accessing the file an empty byte slice is returned.
func (*TPosting) PathFileName ¶
PathFileName returns the article's path-/filename.
func (*TPosting) Set ¶
Set assigns the article's Markdown text.
`aMarkdown` is the actual Markdown text of the article to assign.
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.