fileutil

package
v0.0.0-...-6e5c2bb Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package fileutil provides utilities for working with files and YAML data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base64Resp

type Base64Resp struct {
	Encoded   string
	WordList  string
	Signature string
}

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

func (f FileHelp) CreateDirIfNotExist(location string) error

type FileHelper

type FileHelper interface {
	CreateDirIfNotExist(location string) error
}

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) GetScheme

func (f FileUrlHelp) GetScheme(location string) (string, error)

func (FileUrlHelp) OpenUrl

func (f FileUrlHelp) OpenUrl(location string) ([]byte, 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) WriteUrl

func (f FileUrlHelp) WriteUrl(location string, data []byte) 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

func (y YamlHelp[T]) GetSignature() (sig string, wordList string, err error)

GetSignature returns the signature and word list of the YAML data stored in the YamlHelper.

func (YamlHelp[T]) Open

func (y YamlHelp[T]) Open(location string) (*T, error)

Open reads and parses the YAML data from the specified location.

func (YamlHelp[T]) OpenWithBaseDir

func (y YamlHelp[T]) OpenWithBaseDir(baseDir string, location string) (*T, error)

OpenWithBaseDir reads and parses the YAML data from the specified location, using a base directory.

func (YamlHelp[T]) ParseBase64

func (y YamlHelp[T]) ParseBase64(data string) error

ParseBase64 parses the YAML data from the specified base64 encoded string.

func (YamlHelp[T]) Save

func (y YamlHelp[T]) Save(location string) error

Save writes the YAML data to the specified location.

func (YamlHelp[T]) SaveWithBaseDir

func (y YamlHelp[T]) SaveWithBaseDir(baseDir string, location string) error

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

func (y YamlHelp[T]) SetFromB64(data string) error

SetFromB64 parses the YAML data from the specified base64 encoded string.

Jump to

Keyboard shortcuts

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