Documentation ¶
Overview ¶
Package fileutil provides utilities for working with files and YAML data.
Index ¶
- type Base64Resp
- type FileHelp
- type FileHelper
- type FileUrlHelp
- func (f FileUrlHelp) GetPathFromUrl(location string, preserveFilename bool) (string, error)
- func (f FileUrlHelp) GetScheme(location string) (string, error)
- func (f FileUrlHelp) OpenUrl(location string) ([]byte, error)
- func (f FileUrlHelp) OpenUrlWithBaseDir(baseDir string, location string) ([]byte, error)
- func (f FileUrlHelp) UrlWithBaseDir(baseDir string, location string) (string, error)
- func (f FileUrlHelp) WriteUrl(location string, data []byte) error
- func (f FileUrlHelp) WriteUrlWithBaseDir(baseDir string, location string, data []byte) error
- type FileUrlHelper
- type SerializeHelper
- type YamlHelp
- func (y YamlHelp[T]) Get() T
- func (y YamlHelp[T]) GetBase64() (*Base64Resp, error)
- func (y YamlHelp[T]) GetSignature() (sig string, wordList string, err error)
- func (y YamlHelp[T]) Open(location string) (*T, error)
- func (y YamlHelp[T]) OpenWithBaseDir(baseDir string, location string) (*T, error)
- func (y YamlHelp[T]) ParseBase64(data string) error
- func (y YamlHelp[T]) Save(location string) error
- func (y YamlHelp[T]) SaveWithBaseDir(baseDir string, location string) error
- func (y *YamlHelp[T]) Set(data T) SerializeHelper[T]
- func (y YamlHelp[T]) SetFromB64(data string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Base64Resp ¶
Base64Resp is a struct that contains the base64 encoded data, the word list used to generate the signature,
type FileHelp ¶
type FileHelp struct {
// contains filtered or unexported fields
}
func (FileHelp) CreateDirIfNotExist ¶
type FileHelper ¶
func NewFileHelper ¶
func NewFileHelper() FileHelper
type FileUrlHelp ¶
type FileUrlHelp struct {
// contains filtered or unexported fields
}
func (FileUrlHelp) GetPathFromUrl ¶
func (f FileUrlHelp) GetPathFromUrl(location string, preserveFilename bool) (string, error)
func (FileUrlHelp) OpenUrlWithBaseDir ¶
func (f FileUrlHelp) OpenUrlWithBaseDir(baseDir string, location string) ([]byte, error)
func (FileUrlHelp) UrlWithBaseDir ¶
func (f FileUrlHelp) UrlWithBaseDir(baseDir string, location string) (string, error)
func (FileUrlHelp) WriteUrlWithBaseDir ¶
func (f FileUrlHelp) WriteUrlWithBaseDir(baseDir string, location string, data []byte) error
type FileUrlHelper ¶
type FileUrlHelper interface { GetPathFromUrl(location string, preserveFilename bool) (string, error) GetScheme(location string) (string, error) UrlWithBaseDir(baseDir string, location string) (string, error) OpenUrl(location string) ([]byte, error) OpenUrlWithBaseDir(baseDir string, location string) ([]byte, error) WriteUrl(location string, data []byte) error WriteUrlWithBaseDir(baseDir string, location string, data []byte) error }
func NewFileUrlHelper ¶
func NewFileUrlHelper() FileUrlHelper
type SerializeHelper ¶
type SerializeHelper[T any] interface { Open(location string) (*T, error) OpenWithBaseDir(baseDir string, location string) (*T, error) Save(location string) error SaveWithBaseDir(baseDir string, location string) error Set(data T) SerializeHelper[T] SetFromB64(data string) error Get() T GetBase64() (*Base64Resp, error) ParseBase64(data string) error GetSignature() (sig string, wordList string, err error) }
SerializeHelper is an interface that defines methods for working with YAML data. When using this interface, the type T must be a pointer to a struct. Currently, this is type constrained to any since go does not yet support struct type constraints in interfaces . There is a proposal to add this feature to the language. Breaking the YAGNI principle, this interface is defined to allow for future extensibility. For example, if we want to add a method to this interface that allows for the YAML data to be encrypted, we can do so without breaking backwards compatibility. Future near term functionality is going to also include the ability to safely parse freeform YAML data.
func NewYamlHelper ¶
func NewYamlHelper[T any]() SerializeHelper[T]
NewYamlHelper creates a new instance of YamlHelper with default settings.
type YamlHelp ¶
type YamlHelp[T any] struct { Yaml T // The YAML data // contains filtered or unexported fields }
YamlHelp is a struct that implements the YamlHelper interface.
func (YamlHelp[T]) Get ¶
func (y YamlHelp[T]) Get() T
Get returns the YAML data stored in the YamlHelper.
func (YamlHelp[T]) GetBase64 ¶
func (y YamlHelp[T]) GetBase64() (*Base64Resp, error)
GetBase64 returns the YAML data stored in the YamlHelper as a base64 encoded string.
func (YamlHelp[T]) GetSignature ¶
GetSignature returns the signature and word list of the YAML data stored in the YamlHelper.
func (YamlHelp[T]) OpenWithBaseDir ¶
OpenWithBaseDir reads and parses the YAML data from the specified location, using a base directory.
func (YamlHelp[T]) ParseBase64 ¶
ParseBase64 parses the YAML data from the specified base64 encoded string.
func (YamlHelp[T]) SaveWithBaseDir ¶
SaveWithBaseDir writes the YAML data to the specified location, using a base directory.
func (*YamlHelp[T]) Set ¶
func (y *YamlHelp[T]) Set(data T) SerializeHelper[T]
Set sets the YAML data of the YamlHelper.
func (YamlHelp[T]) SetFromB64 ¶
SetFromB64 parses the YAML data from the specified base64 encoded string.