template/template.go
func (te Expander) Expand() (result string, resultErr error) {
	// It'd better to have no alert description than to kill the whole process
	// if there's a bug in the template.
	defer func() {
		if r := recover(); r != nil {
			var ok bool
			resultErr, ok = r.(error)
			if !ok {
				resultErr = errors.Errorf("panic expanding template %v: %v", te.name, r)
			}
		}
		if resultErr != nil {
			templateTextExpansionFailures.Inc()
		}
	}()

	templateTextExpansionTotal.Inc()

	tmpl, err := text_template.New(te.name).Funcs(te.funcMap).Option("missingkey=zero").Parse(te.text)
	if err != nil {
		return "", errors.Wrapf(err, "error parsing template %v", te.name)
	}
	var buffer bytes.Buffer
	err = tmpl.Execute(&buffer, te.data)
	if err != nil {
		return "", errors.Wrapf(err, "error executing template %v", te.name)
	}
	return buffer.String(), nil
}
func (te Expander) Expand() (result string, resultErr error) {
	// It'd better to have no alert description than to kill the whole process
	// if there's a bug in the template.
	defer func() {
		if r := recover(); r != nil {
			var ok bool
			resultErr, ok = r.(error)
			if !ok {
				resultErr = errors.Errorf("panic expanding template %v: %v", te.name, r)
			}
		}
		if resultErr != nil {
			templateTextExpansionFailures.Inc()
		}
	}()

	templateTextExpansionTotal.Inc()

	tmpl, err := text_template.New(te.name).Funcs(te.funcMap).Option("missingkey=zero").Parse(te.text)
	if err != nil {
		return "", errors.Wrapf(err, "error parsing template %v", te.name)
	}
	var buffer bytes.Buffer
	err = tmpl.Execute(&buffer, te.data)
	if err != nil {
		return "", errors.Wrapf(err, "error executing template %v", te.name)
	}
	return buffer.String(), nil
}
func ( te Expander ) Expand ( ) ( result string , resultErr error ) { // It'd better to have no alert description than to kill the whole process // if there's a bug in the template. defer func ( ) { if r := recover ( ) ; r != nil { var ok bool resultErr , ok = r . ( error ) if ! ok { resultErr = errors . Errorf ( " " , te . name , r ) } } if resultErr != nil { templateTextExpansionFailures . Inc ( ) } } ( ) templateTextExpansionTotal . Inc ( ) tmpl , err := text_template . New ( te . name ) . Funcs ( te . funcMap ) . Option ( " " ) . Parse ( te . text ) if err != nil { return " " , errors . Wrapf ( err , " " , te . name ) } var buffer bytes . Buffer err = tmpl . Execute ( & buffer , te . data ) if err != nil { return " " , errors . Wrapf ( err , " " , te . name ) } return buffer . String ( ) , nil }
// Expand expands a template in text (non-HTML) mode.
Expand expands a template in text ( non - HTML ) mode .