fileloader

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 3 Imported by: 0

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:

  1. Create an instance with the file path you wish to load:

```go

load := fileloader.NewWithFile("/path/to/file")

```

  1. Check it exists (optional):

```go

found, err := load.Exists()

if err != nil {
	panic("File does not exist: " + err.Error())
}

```

  1. 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL