ConfigManager

package
v0.3.22 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

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

type Status[T uc.Enumer] struct {
	// contains filtered or unexported fields
}

Status is a type that represents the status of a set of keys.

func NewStatus added in v0.3.16

func NewStatus[T uc.Enumer](keys []T) *Status[T]

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

func (u *Status[T]) Change(key T, value bool)

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

func (u *Status[T]) GetStatus() map[T]bool

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

func (u *Status[T]) GetValue(key T) bool

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

func (u *Status[T]) IsModified() bool

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

func (u *Status[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Status[T]) UnmarshalJSON added in v0.3.16

func (u *Status[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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