package store
import "github.com/oslokommune/okctl/pkg/client/store"
Package store provides interfaces for more easily interacting with a storage layer
Index ¶
- type Action
- type AddGetBytes
- type AddGetStruct
- type AddStoreBytes
- type AddStoreStruct
- type Alterer
- type FileSystemOption
- func FileSystemCreateDirectories(v bool) FileSystemOption
- func FileSystemOverwriteExisting(v bool) FileSystemOption
- type GetBytesCallback
- type OperationOption
- func WithFilePermissionsMode(mode os.FileMode) OperationOption
- func WithWriteIfNotExists(data []byte) OperationOption
- type Operations
- type PostProcessed
- type PostProcessor
- type PreProcessed
- type PreProcessor
- type ProcessGetStruct
- type Report
Types ¶
type Action ¶
Action contains information about the performed task
type AddGetBytes ¶
type AddGetBytes struct { Name string Callback GetBytesCallback Options []OperationOption }
AddGetBytes contains the fields required for adding a GetBytes operation, useful when operations are created dynamically from a slice or map
type AddGetStruct ¶
type AddGetStruct struct { Name string Into interface{} PostProcessor PostProcessor Options []OperationOption }
AddGetStruct contains the fields required for adding a GetStruct operation, useful when operations are created dynamically from a slice or map
type AddStoreBytes ¶
type AddStoreBytes struct { Name string Data []byte Options []OperationOption }
AddStoreBytes contains the fields required for adding a StoreBytes operation, useful when operations are created dynamically from a slice or map
type AddStoreStruct ¶
type AddStoreStruct struct { Name string Data interface{} PreProcessor PreProcessor Options []OperationOption }
AddStoreStruct contains the fields required for adding a StoreStruct operation, useful when operations are created dynamically from a slice or map
type Alterer ¶
Alterer defines the interface for performing a run-time alteration of the underlying store
func SetBaseDir ¶
SetBaseDir to the provided value
type FileSystemOption ¶
type FileSystemOption func(fs *fileSystem)
FileSystemOption defines how options to the file system can be provided
func FileSystemCreateDirectories ¶
func FileSystemCreateDirectories(v bool) FileSystemOption
FileSystemCreateDirectories ensures that directories are always created before storage operations are performed if set to true
func FileSystemOverwriteExisting ¶
func FileSystemOverwriteExisting(v bool) FileSystemOption
FileSystemOverwriteExisting will ensure that existing files are overwritten if set to true
type GetBytesCallback ¶
GetBytesCallback allows the receiver to process the data immediately without having to go via the report
type OperationOption ¶
type OperationOption func() interface{}
OperationOption provides a means to modify the behavior of an operation, by returning a type or interface that can be evaluated by the implementations.
func WithFilePermissionsMode ¶
func WithFilePermissionsMode(mode os.FileMode) OperationOption
WithFilePermissionsMode will set the permissions of the file
func WithWriteIfNotExists ¶
func WithWriteIfNotExists(data []byte) OperationOption
WithWriteIfNotExists will write the data if the file doesn't exist
type Operations ¶
type Operations interface { // AlterStore makes it possible to perform a modification of the store // during processing. AlterStore(alterers ...Alterer) Operations // StoreStruct will preprocess the data with the given preprocessor // and then store the processed data under the given name, how this // data is stored is given by the underlying implementation. // This method is chainable, so multiple actions may be performed. StoreStruct(name string, data interface{}, preProcessor PreProcessor, options ...OperationOption) Operations // AddStoreStruct makes it possible to add operations when // iterating over a map or slice. AddStoreStruct(operations ...AddStoreStruct) Operations // StoreBytes stores the provided data under the given name, how this // data is stored is given by the underlying implementation. // This method is chainable, so multiple actions may be performed. StoreBytes(name string, data []byte, options ...OperationOption) Operations // AddStoreBytes makes it possible to add operations when // iterating over a map or slice. AddStoreBytes(operations ...AddStoreBytes) Operations // Remove will delete the data under the given name, how this data is // removed is given by the underlying implementation // This method is chainable, so multiple actions may be performed. Remove(name string, options ...OperationOption) Operations // RemoveDir will delete a directory under the given name, how this data is // removed is given by the underlying implementation // This method is chainable, so multiple actions may be performed. RemoveDir(name string, options ...OperationOption) Operations // GetStruct will read the stored data and process it using the // provided post processor, the result will be stored in the report // and can be accessed afterwards. GetStruct(name string, into interface{}, postProcessor PostProcessor, options ...OperationOption) Operations // AddGetStruct makes it possible to add operations when // iterating over a map or slice AddGetStruct(operations ...AddGetStruct) Operations // ProcessGetStruct provides inline processing of a recently // retrieved and processed struct. ProcessGetStruct(name string, storeStruct ProcessGetStruct) Operations // GetBytes will read the stored data and store the result // in the report under the given name, and can be accessed // afterwards. Otherwise, it is possible to provided a // callback, which will be invoked if it is not nil. GetBytes(name string, callback GetBytesCallback, options ...OperationOption) Operations // AddGetBytes makes it possible to add operations when // iterating over a map or slice AddGetBytes(operations ...AddGetBytes) Operations // Do initiates the chain of operations and will either return // an error or a report containing the actions that were performed. Do() (*Report, error) }
Operations defines the functions that can be chained before being executed
func NewFileSystem ¶
func NewFileSystem(baseDir string, fs *afero.Afero, options ...FileSystemOption) Operations
NewFileSystem returns an initialised filesystem store
type PostProcessed ¶
type PostProcessed struct { Format string Data interface{} }
PostProcessed contains information about how the data has been processed.
type PostProcessor ¶
type PostProcessor interface { PostProcess(into interface{}, data []byte) (*PostProcessed, error) Type() string }
PostProcessor defines a type for postprocessing of the data before it is returned
func FromJSON ¶
func FromJSON() PostProcessor
FromJSON provides a postprocessor that unmarshals from yaml into a struct
func FromYAML ¶
func FromYAML() PostProcessor
FromYAML provides a postprocessor that unmarshals yaml data ino a struct
type PreProcessed ¶
PreProcessed contains information about how the data has been processed.
type PreProcessor ¶
type PreProcessor interface { PreProcess(data interface{}) (*PreProcessed, error) Type() string }
PreProcessor defines a type for preprocessing of the data before it is stored
func ToJSON ¶
func ToJSON() PreProcessor
ToJSON provides a preprocessor that marshals a struct to json format
func ToYAML ¶
func ToYAML() PreProcessor
ToYAML provides a preprocessor that marshals a struct to yaml format
type ProcessGetStruct ¶
type ProcessGetStruct func(data interface{}, operations Operations) error
ProcessGetStruct defines the function interface that allows for inline processing of a recently retrieved struct.
type Report ¶
type Report struct { Type string Configuration string Actions []Action Data map[string]interface{} }
Report contains information about what actions were performed
Source Files ¶
filesystem_store.go processor.go store.go
- Version
- v0.0.106 (latest)
- Published
- Oct 21, 2022
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 5 days ago –
Tools for package owners.