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(empty T) 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
- func (m *JSONManager[T]) SetDirPermissions(perm os.FileMode)
- func (m *JSONManager[T]) SetFilePermissions(perm os.FileMode)
- type Status
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 }
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, elem T) *JSONManager[T]
NewJSONManager creates a new JSONManager.
Parameters:
- loc: The path to the JSON file.
- elem: The data to save and load. (only used for type inference)
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(empty T) 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.
func (*JSONManager[T]) SetDirPermissions ¶ added in v0.3.19
func (m *JSONManager[T]) SetDirPermissions(perm os.FileMode)
SetDirPermissions sets the permissions of the directory.
Parameters:
- perm: The permissions of the directory.
func (*JSONManager[T]) SetFilePermissions ¶ added in v0.3.19
func (m *JSONManager[T]) SetFilePermissions(perm os.FileMode)
SetFilePermissions sets the permissions of the file.
Parameters:
- perm: The permissions of the file.
type Status ¶ added in v0.3.16
Status is a type that represents the status of a set of keys.
func NewStatus ¶ added in v0.3.16
NewStatus creates a new Status object.
Parameters:
- keys: The keys of the status.
Returns:
- *Status: The new Status object.
func (*Status[T]) Change ¶ added in v0.3.16
Change changes the status of a key.
Parameters:
- key: The key to change.
- value: The new value of the key.
Behaviors:
- If the key does not exist, the function does nothing.
func (*Status[T]) GetStatus ¶ added in v0.3.16
GetStatus returns the status of the keys.
Returns:
- map[T]bool: The status of the keys.
func (*Status[T]) GetValue ¶ added in v0.3.16
GetValue returns the value of a key.
Parameters:
- key: The key to get the value of.
Returns:
- bool: The value of the key.
Behaviors:
- If the key does not exist, the function returns false.
func (*Status[T]) IsModified ¶ added in v0.3.16
IsModified returns true if the status has been modified.
Returns:
- bool: True if the status has been modified, false otherwise.
func (*Status[T]) MarshalJSON ¶ added in v0.3.16
MarshalJSON implements the json.Marshaler interface.
func (*Status[T]) UnmarshalJSON ¶ added in v0.3.16
UnmarshalJSON implements the json.Unmarshaler interface.