renderer

package
v0.0.0-...-fa214a9 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type D

type D map[string]any

D is the syntax-sugar type for map

type Data

type Data struct {
	// contains filtered or unexported fields
}

Data is the container type for renderer data

func NewData

func NewData(r *http.Request, template string, data D) *Data

NewData sets fields for renderer data

func (*Data) Set

func (d *Data) Set(key string, value any) *Data

Set sets named value to the data container

type Feed

type Feed struct {
	// contains filtered or unexported fields
}

Feed implements Renderer for XML content

func NewFeed

func NewFeed(cfgUI UIConfig, cfgRootURL RootURLConfig) *Feed

NewFeed creates new Feed instance

func (*Feed) Error

func (r *Feed) Error(_ *http.Request, w http.ResponseWriter, code int, err error)

Error renders error to a response writer

func (*Feed) Render

func (r *Feed) Render(w http.ResponseWriter, code int, data *Data)

Render renders the data with response code to a HTTP response writer

type HTML

type HTML struct {
	// contains filtered or unexported fields
}

HTML implements Renderer for HTML content

func NewHTML

func NewHTML(config HTMLConfig, logger *slog.Logger) (*HTML, error)

NewHTML creates new HTML instance

func (*HTML) Error

func (r *HTML) Error(rq *http.Request, w http.ResponseWriter, code int, err error)

Error renders error to a response writer

func (*HTML) Render

func (r *HTML) Render(w http.ResponseWriter, code int, data *Data)

Render renders the data with response code to a HTTP response writer

type HTMLConfig

type HTMLConfig struct {
	Debug         bool
	TemplatesPath string
	UICfg         UIConfig
	RootURLCfg    RootURLConfig
	PluginsCfg    plugin.Config
}

HTMLConfig is configuration for HTML renderer

type Renderer

type Renderer interface {
	// Render renders the data with response code to a response writer
	Render(w http.ResponseWriter, code int, data *Data)
	// Error renders error to a response writer
	Error(rq *http.Request, w http.ResponseWriter, code int, err error)
}

Renderer is the interface for rendering data to a client in required format

type RootURLConfig

type RootURLConfig struct {
	Scheme string `env:"ROOT_URL_SCHEME,default=http"`
	Host   string `env:"ROOT_URL_HOST"`
	Path   string `env:"ROOT_URL_PATH,default=/"`
}

RootURLConfig is the configuration for app root url

func (RootURLConfig) URL

func (u RootURLConfig) URL(r *http.Request) *url.URL

URL returns the URL for currently configured root url

type UIConfig

type UIConfig struct {
	Theme       string `env:"UI_THEME,default=foundation6"`
	Author      string `env:"UI_AUTHOR,default=Vladimir Garvardt"`
	Email       string `env:"UI_EMAIL,default=vgarvardt@gmail.com"`
	Description string `env:"UI_DESCRIPTION,default=rKlotz - simple golang-driven blog engine"`
	Language    string `env:"UI_LANGUAGE,default=en"`
	Title       string `env:"UI_TITLE,default=rKlotz"`
	Heading     string `env:"UI_HEADING,default=rKlotz"`
	Intro       string `env:"UI_INTRO,default=simple golang-driven blog engine"`
	// DateFormat is format for posts, see http://golang.org/pkg/time/#Time.Format
	DateFormat string `env:"UI_DATEFORMAT,default=2 Jan 2006"`
	AboutPath  string `env:"UI_ABOUT_PATH,default=/etc/rklotz/about.tpl"`
}

UIConfig is the configuration for user interface

Jump to

Keyboard shortcuts

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