web

package
v0.0.0-...-9008a76 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeyHost is the configuration key for the host.
	KeyHost string = "host"
	// KeyPort is the configuration key for the port.
	KeyPort string = "port"
	// KeyStaticDir is the configuration key to know where
	// static assets are stored (in case we want to serve them
	// from this application instead of using a third party
	// web server).
	KeyStaticDir string = "staticdir"
	// KeyHTMLTemplatesDir is the directory where the HTML templates
	// are stored.
	KeyHTMLTemplatesDir string = "HTMLtemplates"
)

Variables

This section is empty.

Functions

func NewMultiRenderEngine

func NewMultiRenderEngine(t *Templates) render.HTMLRender

NewMultiRenderEngine creates a render engine from the Templates struct. Currently, it only provides a `trans` function to templates to be able to translate content.

func NewMultiRenderEngineFromDirs

func NewMultiRenderEngineFromDirs(dirPaths ...string) render.HTMLRender

NewMultiRenderEngineFromDirs scan a list of directories to search for templates under directories named `html_templates` (and template fragments under `html_templates/inc` dirs).

Types

type Config

type Config struct {
	Port             int
	Host             string
	HTMLTemplatesDir string
	ServeStatic      bool
	StaticDir        string
}

Config contains the information about a web service to run.

func NewDefaultConfig

func NewDefaultConfig(confPrefix string) *Config

NewDefaultConfig creates the default configuration for a service to run.

func (*Config) Address

func (c *Config) Address() string

Address returns the address of the web service

type HTMLWrapper

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

HTMLWrapper is a "dumb" wrapper over the multitemplate implementation, that on every request reloads the templates: so it should not be used in production, but is useful to use it while developing, to have live updates from the loaded templates.

func NewHTMLRender

func NewHTMLRender(dirPaths ...string) *HTMLWrapper

NewHTMLRender creates a

func (*HTMLWrapper) Instance

func (h *HTMLWrapper) Instance(a string, b interface{}) render.Render

Instance wraps the call to `Instance` for a fresh new MultiRenderEngine from the stored dirPaths in HTMLWrapper

type Templates

type Templates struct {
	Pages    map[string]string
	Includes []string
}

Templates contains map of pages to be used as templates with a list of files that are used as "fragments" to be used by those templates.

func (*Templates) Collect

func (t *Templates) Collect(dirName string)

Collect searches a give `dirName` directory for files under directories called `html_templates` for main templates (and files under `html_templates/inc` dir for additional fragments to be used in main teamplates).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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