示例#1
0
// NewTemplate creates and parses a new Consul Template template at the given
// path. If the template does not exist, an error is returned. During
// initialization, the template is read and is parsed for dependencies. Any
// errors that occur are returned.
func NewTemplate(path string) (*Template, error) {
	template := &Template{Path: path}
	if err := template.init(); err != nil {
		return nil, err
	}

	return template, nil
}
示例#2
0
// NewTemplate creates and parses a new Consul Template template at the given
// path. If the template does not exist, an error is returned. During
// initialization, the template is read and is parsed for dependencies. Any
// errors that occur are returned.
func NewTemplate(path, leftDelim, rightDelim string) (*Template, error) {
	template := &Template{
		Path:       path,
		LeftDelim:  leftDelim,
		RightDelim: rightDelim,
	}
	if err := template.init(); err != nil {
		return nil, err
	}

	return template, nil
}
示例#3
0
文件: template.go 项目: nak3/nomad
// NewTemplate creates and parses a new Consul Template template at the given
// path. If the template does not exist, an error is returned. During
// initialization, the template is read and is parsed for dependencies. Any
// errors that occur are returned.
func NewTemplate(path, contents, leftDelim, rightDelim string) (*Template, error) {
	// Validate that we are either given the path or the explicit contents
	pathEmpty, contentsEmpty := path == "", contents == ""
	if !pathEmpty && !contentsEmpty {
		return nil, errors.New("Either specify template path or content, not both")
	} else if pathEmpty && contentsEmpty {
		return nil, errors.New("Must specify template path or content")
	}

	template := &Template{
		Path:       path,
		Contents:   contents,
		LeftDelim:  leftDelim,
		RightDelim: rightDelim,
	}
	if err := template.init(); err != nil {
		return nil, err
	}

	return template, nil
}