Documentation ¶
Overview ¶
Package file provides functions that combine file handling, JSON marshaling and file system abstraction.
Index ¶
- Variables
- type Handler
- func (h *Handler) CopyDir(src, dst string, opts ...Option) error
- func (h *Handler) CopyFile(src, dst string, opts ...Option) error
- func (h *Handler) IsEmpty(dirName string) (bool, error)
- func (h *Handler) MkdirAll(name string) error
- func (h *Handler) Read(name string) ([]byte, error)
- func (h *Handler) ReadJSON(name string, content any) error
- func (h *Handler) ReadYAML(name string, content any) error
- func (h *Handler) ReadYAMLStrict(name string, content any) error
- func (h *Handler) Remove(name string) error
- func (h *Handler) RemoveAll(name string) error
- func (h *Handler) RenameFile(a, b string) error
- func (h *Handler) Stat(name string) (fs.FileInfo, error)
- func (h *Handler) Write(name string, data []byte, options ...Option) error
- func (h *Handler) WriteJSON(name string, content any, options ...Option) error
- func (h *Handler) WriteYAML(name string, content any, options ...Option) (err error)
- type Option
Constants ¶
This section is empty.
Variables ¶
var ( // OptNone is a no-op. OptNone = Option{optNone} // OptOverwrite overwrites an existing file. OptOverwrite = Option{optOverwrite} // OptMkdirAll creates the path to the file. OptMkdirAll = Option{optMkdirAll} // OptAppend appends to the file. OptAppend = Option{optAppend} )
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles file interaction.
func (*Handler) CopyDir ¶ added in v2.8.0
CopyDir copies the src directory recursively into dst with the given options. OptMkdirAll is always set. CopyDir does not follow symlinks.
func (*Handler) CopyFile ¶ added in v2.8.0
CopyFile copies the file from src to dst with the given options, respecting file permissions.
func (*Handler) MkdirAll ¶ added in v2.3.0
MkdirAll creates a directory path and all parents that does not exist yet.
func (*Handler) ReadJSON ¶
ReadJSON reads a JSON file from name and unmarshals it into the content interface. The interface content must be a pointer to a JSON marchalable object.
func (*Handler) ReadYAML ¶
ReadYAML reads a YAML file from name and unmarshals it into the content interface. The interface content must be a pointer to a YAML marshalable object.
func (*Handler) ReadYAMLStrict ¶
ReadYAMLStrict does the same as ReadYAML, but fails if YAML contains fields that are not specified in content.
func (*Handler) RenameFile ¶ added in v2.12.0
RenameFile renames a file, overwriting any existing file at the destination.
func (*Handler) Stat ¶
Stat returns a FileInfo describing the named file, or an error, if any happens.