helpers

package
v0.0.0-...-1bc63cf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2019 License: GPL-3.0 Imports: 18 Imported by: 12

Documentation

Index

Constants

View Source
const SettingsFileName = "settings.json"

SettingsFileName is the name of the settings file. Could be customized to anything you want but _should_ end in .json

Variables

View Source
var (

	// Store ...
	Store = sessions.NewCookieStore(key)
)

Functions

func CheckIfStringContainsHTML

func CheckIfStringContainsHTML(path string, templ *template.Template) error

CheckIfStringContainsHTML checks if the string contains the .html suffix.

func CheckIfUserIsPartOfGroup

func CheckIfUserIsPartOfGroup(db *sql.DB, username string, group string) (bool, error)

CheckIfUserIsPartOfGroup checks if the user sent in is a part of the group sent in.

func ConvertInterfaceToHashmap

func ConvertInterfaceToHashmap(inInterface interface{}) (map[string]interface{}, error)

ConvertInterfaceToHashmap converts an interface to a hashmap.

func CreateDBHandler

func CreateDBHandler() (*sql.DB, error)

CreateDBHandler returns a database handler to the database exactly as defined in the settings.json file.

func CreateDBHandlerWithDB

func CreateDBHandlerWithDB(database string) (*sql.DB, error)

CreateDBHandlerWithDB returns a database handler to the database as defined in the settings.json file without regards to the database_name config option. Is very useful for unit tests.

func GenerateRandomStringURLSafe

func GenerateRandomStringURLSafe(n int) (string, error)

GenerateRandomStringURLSafe returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateSlug

func GenerateSlug(input string) string

GenerateSlug generates a slug from an input name.

func GetSettingFromName

func GetSettingFromName(db *sql.DB, name string) (string, error)

GetSettingFromName returns the setting value from the database by the setting name.

func GetSettings

func GetSettings(db *sql.DB) (map[string]string, error)

GetSettings returns all of the settings from the database as a hashmap.

func GetUsernameFromRequest

func GetUsernameFromRequest(r *http.Request) (string, error)

GetUsernameFromRequest gets the username from the storage and returns it or an error.

func HandleError

func HandleError(err error)

HandleError logs all errors and writes them to file.

func InternalServerError

func InternalServerError(w http.ResponseWriter)

InternalServerError returns an internal server error.

func Markdown

func Markdown(arg string) template.HTML

Markdown converts the markdown to HTML. To be used inside templates.

func ParseTemplates

func ParseTemplates() *template.Template

ParseTemplates parses the HTML templates in the templates folder. Including any HTML templates in subdirectories.

func RenderTemplate

func RenderTemplate(r *http.Request, w http.ResponseWriter, tmpl string, data interface{})

RenderTemplate renders the HTML file as sent in by the 'tmpl' variable and uses the 'data' interface as well as adds more data necessary for running the application.

func UserIsAdmin

func UserIsAdmin(r *http.Request) bool

UserIsAdmin function checks if the user is an administrator and returns the result as a boolean.

Types

type Configuration

type Configuration struct {
	DatabaseUser     string
	DatabasePassword string
	DatabaseHost     string
	DatabasePort     string
	DatabaseName     string
}

Configuration is the data stored in the settings.json file in a go struct.

type FooterPage

type FooterPage struct {
	Title    string
	Slug     string
	Category string
}

FooterPage contains the data used in the footer items

func GetFooterPages

func GetFooterPages(db *sql.DB) ([]FooterPage, error)

GetFooterPages returns all of the footer pages from the database

type Path

type Path struct {
	Name string
	Link string
}

Path is used in toolbar and a list of path should be the way to get to the current URL.

type ToolbarPage

type ToolbarPage struct {
	Title string
	Slug  string
}

ToolbarPage contains the data used in the toolbar items

func GetToolbarPages

func GetToolbarPages(db *sql.DB) ([]ToolbarPage, error)

GetToolbarPages returns all of the toolbar pages from the database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL