Documentation ¶
Index ¶
- type JSONEncoder
- type JSONManager
- func (m *JSONManager[T]) ChangeData(data T)
- func (m *JSONManager[T]) ChangePath(path string)
- func (m *JSONManager[T]) Create() error
- func (m *JSONManager[T]) Delete() error
- func (m *JSONManager[T]) Exists() (bool, error)
- func (m *JSONManager[T]) GetData() T
- func (m *JSONManager[T]) GetLocation() string
- func (m *JSONManager[T]) GetPermissions() [2]os.FileMode
- func (m *JSONManager[T]) Load() (T, error)
- func (m *JSONManager[T]) Save() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JSONEncoder ¶
type JSONEncoder interface { json.Marshaler json.Unmarshaler // Empty returns the default values of the data. // // Returns: // - JSONEncoder: The default values of the data. Empty() json.Marshaler }
JSONEncoder is an interface for encoding and decoding JSON data.
type JSONManager ¶
type JSONManager[T JSONEncoder] struct { // contains filtered or unexported fields }
JSONManager is a manager for saving and loading data to and from a JSON file.
func NewJSONManager ¶
func NewJSONManager[T JSONEncoder](loc string, dirPerm os.FileMode) *JSONManager[T]
NewJSONManager creates a new JSONManager.
Parameters:
- loc: The path to the JSON file.
- dirPerm: The permissions for the directory.
Returns:
- *JSONManager[T]: The new JSONManager.
func (*JSONManager[T]) ChangeData ¶
func (m *JSONManager[T]) ChangeData(data T)
ChangeData changes the data of the JSONManager[T].
Parameters:
- data: The new data to save and load.
func (*JSONManager[T]) ChangePath ¶
func (m *JSONManager[T]) ChangePath(path string)
ChangePath changes the path of the JSON file.
Parameters:
- path: The new path to the JSON file.
func (*JSONManager[T]) Create ¶
func (m *JSONManager[T]) Create() error
Create creates a new JSON file at the location of the JSONManager[T].
Returns:
- error: An error if one occurred while creating the file.
func (*JSONManager[T]) Delete ¶
func (m *JSONManager[T]) Delete() error
Delete deletes the file at the location.
Returns:
- error: An error if one occurred while deleting the file.
func (*JSONManager[T]) Exists ¶
func (m *JSONManager[T]) Exists() (bool, error)
Exists checks if a file exists at the location of the JSONManager[T].
Returns:
- bool: A boolean indicating whether the file exists.
- error: An error if one occurred while checking the file.
func (*JSONManager[T]) GetData ¶ added in v0.3.14
func (m *JSONManager[T]) GetData() T
GetData returns the data of the JSONManager[T].
Returns:
- T: The data of the JSONManager[T].
func (*JSONManager[T]) GetLocation ¶
func (m *JSONManager[T]) GetLocation() string
GetLocation returns the location of the file.
Returns:
- string: The location of the file.
func (*JSONManager[T]) GetPermissions ¶
func (m *JSONManager[T]) GetPermissions() [2]os.FileMode
GetPermissions returns the permissions of the file.
Returns:
- [2]os.FileMode: An array of os.FileMode representing the permissions of the directory and file.
func (*JSONManager[T]) Load ¶
func (m *JSONManager[T]) Load() (T, error)
Load loads the data from the JSON file.
Returns:
- error: An error if there was an issue loading the data.
func (*JSONManager[T]) Save ¶
func (m *JSONManager[T]) Save() error
Save saves the data to the JSON file. It will overwrite the file if it already exists.
Returns:
- error: An error if there was an issue saving the data.