view

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package view provides ways to textually describe computed outputs through template views.

Index

Constants

View Source
const (
	// Extension used for template files
	Extension = ".tpl"

	// Name of the default template file, without extension.
	Name TemplateName = "default"

	// Template default content.
	Template = `` /* 1152-byte string literal not displayed */

)
View Source
const (
	// Resolving status
	Resolving uint8 = iota + 1

	// ResolvingSlowly status
	ResolvingSlowly

	// UnderControl status
	UnderControl

	// BarelyUnderControl status
	BarelyUnderControl

	// LoosingControl status
	LoosingControl

	// HardToControl status
	HardToControl

	// OutOfControl status
	OutOfControl
)

Variables

This section is empty.

Functions

This section is empty.

Types

type TemplateName

type TemplateName string

TemplateName is a name of a template

func (TemplateName) String

func (n TemplateName) String() string

type View

type View struct {
	Country string
	Updated time.Time

	Status struct {
		Score     uint8
		Resolving bool
		Improving bool
	}

	Current struct {
		Rate  float64
		Cases int
	}

	Comparison struct {
		Rate        float64
		RateOfRates float64
	}

	Recovery struct {
		DaysTo1     float64
		DaysToStart float64
		DaysToPeak  float64
		PeakCases   float64
	}

	Forecast struct {
		Growth string
		Cases  float64
		Days   int
	}
	// contains filtered or unexported fields
}

View of a template. Use View's fields to pass information to your template.

func New

func New(dir string, selected TemplateName) (*View, error)

New template view created from a selected template in the template directory dir. If the template directory has no template files (*.tpl), a default template will be created with content from Template. If selected is empty, the default template (Template) will be used.

The following custom template functions can be used:

  • print LANG ARGUMENTS, like fmt.Print, but formatted according to local LANG (see doc for golang.org/x/text/message);
  • printf LANG FORMAT ARGUMENTS, like fmt.Printf, but formatted according to local LANG (see doc for golang.org/x/text/message);
  • fmtdate LAYOUT TIME, like t.Format(LAYOUT), where t is the TIME object.

func (*View) Execute

func (v *View) Execute(w io.Writer) error

Execute a selected template, wrapping around text/template.Execute.

Jump to

Keyboard shortcuts

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