Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileLoader ¶
type FileLoader interface {
// The file path that we wish to load.
Filename() string
// Check if the file exists.
Exists() (bool, error)
// Read the file and return a byte array of its content.
Load() ([]byte, error)
}
File loader.
A utility that provides file opening functionality wrapped in a mockable interface.
To use:
- Create an instance with the file path you wish to load:
```go
load := fileloader.NewWithFile("/path/to/file")
```
- Check it exists (optional):
```go
found, err := load.Exists()
if err != nil {
panic("File does not exist: " + err.Error())
}
```
- Load your file:
```go
data, err := load.Load()
if err != nil {
panic("Could not load file: " + err.Error())
}
```
The `Load` method returns the file content as a byte array.
func NewWithFile ¶
func NewWithFile(filename string) FileLoader
Create a new FileLoader object with the given file name.
Click to show internal directories.
Click to hide internal directories.