Documentation ¶
Overview ¶
Package fs provides filesystem utilities for ghx.
Index ¶
- func CopyFile(src, dst string) error
- func EnsureDir(dir string) error
- func EnsureFile(file string) error
- func Exists(path string) (bool, error)
- func ReadJSONFile[T any](file string, val *T) error
- func ReadYAMLFile[T any](file string, val *T) error
- func WriteFile(file string, content []byte, permissions os.FileMode) error
- func WriteJSONFile(file string, val interface{}) error
- type MultipartFileWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureDir ¶
EnsureDir ensures that the given directory exists under the ghx data home directory.
func EnsureFile ¶
EnsureFile ensures that the given file exists under the ghx data home directory. If the file does not exist, it will be created.
To ensure everything is working as expected, the method will also ensure that the directory of the file exists.
func ReadJSONFile ¶
ReadJSONFile reads the given path as a JSON file under the ghx data home directory and unmarshal it into the given value.
func ReadYAMLFile ¶
ReadYAMLFile reads the given path as a YAML file.
func WriteFile ¶
WriteFile ensures that the given file exists under the ghx data home directory. If the file does not exist, it will be created and the given content will be written to it.
To ensure everything is working as expected, the method will also ensure that the directory of the file exists.
func WriteJSONFile ¶
WriteJSONFile writes the given value to the given path as a JSON file under the ghx data home directory.
Types ¶
type MultipartFileWriter ¶
type MultipartFileWriter struct {
// contains filtered or unexported fields
}
MultipartFileWriter allows writing a file in chunks first and then merging the chunks into a single file. This is useful for uploading large files in chunks while ensuring files are not corrupted in case of network errors or not ordered chunk uploads.
func NewMultipartFileWriter ¶
func NewMultipartFileWriter(root string) (*MultipartFileWriter, error)
NewMultipartFileWriter creates a new MultipartFileWriter that writes files to the specified root directory.
func (*MultipartFileWriter) Merge ¶
func (w *MultipartFileWriter) Merge() error
Merge combines the uploaded part files into separate intended files and removes the part files.