Documentation
¶
Overview ¶
Package encoding provides utilities for encoding and decoding data.
Index ¶
- func DirExists(path string) bool
- func EnsureDir(path string) error
- func EnsureParentDir(filePath string) error
- func FileExists(path string) bool
- func LoadJSON[T any](path string) (*T, error)
- func MustLoadJSON[T any](path string) *T
- func ParseJSON[T any](data []byte) (*T, error)
- func ReadFile(path string) ([]byte, error)
- func SaveJSON[T any](path string, value T) error
- func ToJSON[T any](value T) ([]byte, error)
- func ToJSONIndent[T any](value T) ([]byte, error)
- func WriteFile(path string, data []byte, perm os.FileMode) error
- func WriteFileSecure(path string, data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureDir ¶
EnsureDir creates a directory and all parent directories if they don't exist. Uses 0755 permissions.
func EnsureParentDir ¶
EnsureParentDir ensures the parent directory of a file path exists.
func FileExists ¶
FileExists checks if a file exists at the given path.
func LoadJSON ¶
LoadJSON reads a JSON file and unmarshals it into the provided value. Returns nil, nil if the file does not exist. Returns an error for other file access or parsing issues.
func MustLoadJSON ¶
MustLoadJSON is like LoadJSON but panics on error. Use only when the file is expected to exist and be valid.
func ParseJSON ¶
ParseJSON unmarshals JSON data into the provided type. Returns an error if parsing fails.
func ReadFile ¶
ReadFile reads the entire contents of a file. Returns nil, nil if the file does not exist.
func SaveJSON ¶
SaveJSON marshals the value to JSON and writes it to the specified path. Creates parent directories if they don't exist. Uses 0600 permissions for the file.
func ToJSONIndent ¶
ToJSONIndent marshals a value to indented JSON bytes. Returns an error if marshaling fails.
func WriteFile ¶
WriteFile writes data to a file with the specified permissions. Creates parent directories if they don't exist.
func WriteFileSecure ¶
WriteFileSecure writes data to a file with 0600 permissions (owner read/write only). Use for sensitive data like tokens or configs.
Types ¶
This section is empty.