enbas/internal/utilities/file.go
Dan Anglin 3d20adfa57
chore: REUSE.toml
- Replace .reuse/dep5 with the new REUSE.toml file.
- Add licensing information to REUSE.toml and remove the licensing
  headers from the source files.
2024-08-01 04:01:38 +01:00

28 lines
504 B
Go

package utilities
import (
"errors"
"fmt"
"os"
)
func ReadFile(path string) (string, error) {
data, err := os.ReadFile(path)
if err != nil {
return "", fmt.Errorf("unable to read the data from the file: %w", err)
}
return string(data), nil
}
func FileExists(path string) (bool, error) {
if _, err := os.Stat(path); err != nil {
if errors.Is(err, os.ErrNotExist) {
return false, nil
}
return false, fmt.Errorf("unable to check if the file exists: %w", err)
}
return true, nil
}