Documentation ¶
Overview ¶
Package file provides functions that combine file handling, JSON marshaling and file system abstraction.
Index ¶
- Variables
- type Handler
- 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) 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} )
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles file interaction.
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 marchalable object.
func (*Handler) ReadYAMLStrict ¶
ReadYAMLStrict does the same as ReadYAML, but fails if YAML contains fields that are not specified in content.
func (*Handler) Stat ¶
Stat returns a FileInfo describing the named file, or an error, if any happens.