Example #1
1
File: util.go Project: NetSys/quilt
// WriteFile writes 'data' to the file 'filename' with the given permissions.
func WriteFile(filename string, data []byte, perm os.FileMode) error {
	a := afero.Afero{
		Fs: AppFs,
	}
	return a.WriteFile(filename, data, perm)
}
Example #2
0
File: util.go Project: NetSys/quilt
// ReadFile returns the contents of `filename`.
func ReadFile(filename string) (string, error) {
	a := afero.Afero{
		Fs: AppFs,
	}
	fileBytes, err := a.ReadFile(filename)
	if err != nil {
		return "", err
	}
	return string(fileBytes), nil
}
Example #3
0
File: io.go Project: NetSys/quilt
func fileContents(file string) (string, error) {
	a := afero.Afero{
		Fs: appFs,
	}
	contents, err := a.ReadFile(file)
	if err != nil {
		return "", err
	}
	return string(contents), nil
}
Example #4
0
File: io.go Project: NetSys/quilt
func writeTo(file string, message string) error {
	a := afero.Afero{
		Fs: appFs,
	}

	f, err := a.OpenFile(file, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
	if err != nil {
		logrus.WithError(err).Errorf("Couldn't open %s for writing", file)
		return err
	}

	defer f.Close()
	_, err = f.WriteString(message)
	return err
}
Example #5
0
File: io.go Project: NetSys/quilt
func overwrite(file string, message string) error {
	a := afero.Afero{
		Fs: appFs,
	}
	return a.WriteFile(file, []byte(message), 0666)
}