filestore

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingKey = errors.New("missing key - unable to save data")
)

Functions

This section is empty.

Types

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver holds the config and interacts with the underlying file store.

func New

func New(baseDir string, options *Options) (*Driver, error)

New creates a new driver at the given location, and returns a *Driver for further interaction. By default will use teh JSONMarshaler.

func (*Driver) Read

func (d *Driver) Read(key string, v interface{}) error

Read the content from [key] into [v].

func (*Driver) Write

func (d *Driver) Write(key string, v interface{}) error

Write the value [v] to the [key], using the marshaler.

type JSONMarshaler

type JSONMarshaler struct {
}

JSONMarshaler uses the JSON file format.

func (JSONMarshaler) GetFileExtension

func (m JSONMarshaler) GetFileExtension() string

func (JSONMarshaler) Marshal

func (m JSONMarshaler) Marshal(v interface{}) ([]byte, error)

func (JSONMarshaler) Unmarshal

func (m JSONMarshaler) Unmarshal(b []byte, v interface{}) error

type Logger

type Logger interface {
	Fatal(string, ...interface{})
	Error(string, ...interface{})
	Warn(string, ...interface{})
	Info(string, ...interface{})
	Debug(string, ...interface{})
	Trace(string, ...interface{})
}

Logger is a generic logger

type Marshaler

type Marshaler interface {
	Marshal(interface{}) ([]byte, error)
	Unmarshal([]byte, interface{}) error
	GetFileExtension() string
}

Marshaler is used to read/write the data

type Options

type Options struct {
	Logger
	Marshaler
	Placer
}

Options for optional config

type Placer

type Placer interface {
	GetPath(key string) string
}

type SimplePlacer

type SimplePlacer struct{}

func (SimplePlacer) GetPath

func (p SimplePlacer) GetPath(key string) string

type YAMLMarshaler

type YAMLMarshaler struct {
}

JSONMarshaler uses the YAML file format.

func (YAMLMarshaler) GetFileExtension

func (m YAMLMarshaler) GetFileExtension() string

func (YAMLMarshaler) Marshal

func (m YAMLMarshaler) Marshal(v interface{}) ([]byte, error)

func (YAMLMarshaler) Unmarshal

func (m YAMLMarshaler) Unmarshal(b []byte, v interface{}) error

Jump to

Keyboard shortcuts

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