templater

package
v0.107.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound             = errors.New("template not found")
	ErrPathTraversalBlocked = errors.New("path traversal blocked")
)
View Source
var (
	ErrNotAuthorized = errors.New("unauthorized")
	// ErrTemplateFailed is an error generated by the "fail" template function.
	ErrTemplateFailed = errors.New("")
)
View Source
var ErrBadFuncRet = errors.New("wrong number of return values")

Functions

func WrapFuncMapWithData

func WrapFuncMapWithData(funcMap template.FuncMap, data interface{}) template.FuncMap

WrapFuncMapWithData wraps a funcMap to a FuncMap that passes data as a first element when calling each element.

Types

type AuthService

type AuthService interface {
	auth.Authorizer
	auth.CredentialsCreator
}

type ControlledParams

type ControlledParams struct {
	Ctx   context.Context
	Phase Phase
	Auth  AuthService
	// Headers are the HTTP response headers.  They may only be modified
	// during PhasePrepare.
	Header http.Header
	// User is the user expanding the template.
	User *auth_model.User
	// Store is a place for funcs to keep stuff around, mostly between
	// phases.  Each func should use its name as its index.
	Store map[string]interface{}
}

type Credentials

type Credentials struct {
	Key, Secret string
}

type Expander

type Expander interface {
	// Expand serves the template into w using the parameters specified
	// in params.  If during expansion a template function fails,
	// returns an error without writing anything to w.  (However if
	// expansion fails for other reasons, Expand may write to w!)
	Expand(w io.Writer, params *Params) error
}

Expander is a template that may be expanded as requested by users.

func MakeExpander

func MakeExpander(name, tmpl string, cfg *config.Config, auth AuthService) (Expander, error)

MakeExpander creates an expander for the text of tmpl.

type ExpanderMap

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

ExpanderMap reads and caches Expanders from a fs.FS. Currently, it provides no uncaching as it is only used with a prebuilt FS.

func NewExpanderMap

func NewExpanderMap(fs fs.FS, cfg *config.Config, auth AuthService) *ExpanderMap

func (*ExpanderMap) Get

func (em *ExpanderMap) Get(_ context.Context, _, name string) (Expander, error)

type Params

type Params struct {
	// Controlled is the data visible to functions to control expansion.
	// It is _not_ directly visible to templates for expansion.
	Controlled *ControlledParams
	// Data is directly visible to templates for expansion, with no
	// authorization required.
	Data *UncontrolledData
}

Params parametrizes a single template expansion.

type Phase

type Phase string
const (
	PhasePrepare Phase = "prepare"
	PhaseExpand  Phase = "expand"
)

type Service

type Service interface {
	Expand(ctx context.Context, w http.ResponseWriter, user *model.User, templateName string, query map[string]string) error
}

func NewService

func NewService(fs fs.FS, cfg *config.Config, auth AuthService) Service

type UncontrolledData

type UncontrolledData struct {
	// UserName is the name of the executing user.
	Username string
	// Query is the (parsed) querystring of the HTTP access.
	Query map[string]string
}

Jump to

Keyboard shortcuts

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