Пример #1
0
func Exists(filename string) bool {
	_, err := sigil.LookPath(filename)
	if err != nil {
		return false
	}
	return true
}
Пример #2
0
func Exists(in interface{}) (bool, error) {
	filename, _, ok := sigil.String(in)
	if !ok {
		return false, fmt.Errorf("exists must be given a string")
	}
	_, err := sigil.LookPath(filename)
	if err != nil {
		return false, nil
	}
	return true, nil
}
Пример #3
0
func Include(filename string, args ...interface{}) (string, error) {
	path, err := sigil.LookPath(filename)
	if err != nil {
		return "", err
	}
	data, err := ioutil.ReadFile(path)
	if err != nil {
		return "", err
	}
	sigil.PushPath(filepath.Dir(path))
	defer sigil.PopPath()
	render, err := render(data, args, filepath.Base(path))
	return render.String(), err
}
Пример #4
0
func read(file interface{}) ([]byte, error) {
	stdin, ok := file.(stdinStr)
	if ok {
		return []byte(stdin), nil
	}
	path, ok := file.(string)
	if !ok {
		return []byte{}, fmt.Errorf("file must be path string or stdin")
	}
	filepath, err := sigil.LookPath(path)
	if err != nil {
		return []byte{}, err
	}
	data, err := ioutil.ReadFile(filepath)
	if err != nil {
		return []byte{}, err
	}
	return data, nil
}
Пример #5
0
func read(file interface{}) ([]byte, error) {
	reader, ok := file.(sigil.NamedReader)
	if ok {
		return ioutil.ReadAll(reader)
	}
	path, _, ok := sigil.String(file)
	if !ok {
		return []byte{}, fmt.Errorf("file must be stream or path string")
	}
	filepath, err := sigil.LookPath(path)
	if err != nil {
		return []byte{}, err
	}
	data, err := ioutil.ReadFile(filepath)
	if err != nil {
		return []byte{}, err
	}
	return data, nil
}