persist

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadVersion indicates that the version number of the file is not
	// compatible with the current codebase.
	ErrBadVersion = errors.New("incompatible version")

	// ErrBadHeader indicates that the file opened is not the file that was
	// expected.
	ErrBadHeader = errors.New("wrong header")
)

Functions

func Load added in v0.3.3

func Load(meta Metadata, data interface{}, r io.Reader) error

Load loads json data from a reader.

func LoadFile added in v0.3.3

func LoadFile(meta Metadata, data interface{}, filename string) error

LoadFile loads json data from a file.

func NewSafeFile added in v1.0.0

func NewSafeFile(filename string) (*safeFile, error)

NewSafeFile returns a file that can atomically be written to disk, minimizing the risk of corruption.

func RandomSuffix added in v1.0.0

func RandomSuffix() string

RandomSuffix returns a 20 character base32 suffix for a filename. There are 100 bits of entropy, and a very low probability of colliding with existing files unintentionally.

func Save added in v0.3.3

func Save(meta Metadata, data interface{}, w io.Writer) error

Save saves json data to a writer.

func SaveFile added in v0.3.3

func SaveFile(meta Metadata, data interface{}, filename string) error

SaveFile atomically saves json data to a file.

func SaveFileSync added in v1.0.0

func SaveFileSync(meta Metadata, data interface{}, filename string) error

SaveFileSync atomically saves json data to a file and then syncs to disk.

Types

type BoltDatabase added in v1.0.0

type BoltDatabase struct {
	Metadata
	*bolt.DB
}

BoltDatabase is a persist-level wrapper for the bolt database, providing extra information such as a version number.

func OpenDatabase added in v1.0.0

func OpenDatabase(md Metadata, filename string) (*BoltDatabase, error)

OpenDatabase opens a database and validates its metadata.

func (*BoltDatabase) Close added in v1.0.0

func (db *BoltDatabase) Close() error

Close closes the database.

type Logger added in v1.0.0

type Logger struct {
	*log.Logger
	// contains filtered or unexported fields
}

Logger is a wrapper for the standard library logger that enforces logging with the Sia-standard settings. It also supports a Close method, which attempts to close the underlying io.Writer.

func NewFileLogger added in v1.0.0

func NewFileLogger(logFilename string) (*Logger, error)

NewFileLogger returns a logger that logs to logFilename. The file is opened in append mode, and created if it does not exist.

func NewLogger added in v1.0.0

func NewLogger(w io.Writer) *Logger

NewLogger returns a logger that can be closed. Calls should not be made to the logger after 'Close' has been called.

func (*Logger) Close added in v1.0.0

func (l *Logger) Close() error

Close logs a shutdown message and closes the Logger's underlying io.Writer, if it is also an io.Closer.

func (*Logger) Critical added in v1.0.0

func (l *Logger) Critical(v ...interface{})

Critical logs a message with a CRITICAL prefix that guides the user to the Sia github tracker. If debug mode is enabled, it will also write the message to os.Stderr and panic. Critical should only be called if there has been a developer error, otherwise Severe should be called.

func (*Logger) Debug added in v1.0.0

func (l *Logger) Debug(v ...interface{})

Debug is equivalent to Logger.Print when build.DEBUG is true. Otherwise it is a no-op.

func (*Logger) Debugf added in v1.0.0

func (l *Logger) Debugf(format string, v ...interface{})

Debugf is equivalent to Logger.Printf when build.DEBUG is true. Otherwise it is a no-op.

func (*Logger) Debugln added in v1.0.0

func (l *Logger) Debugln(v ...interface{})

Debugln is equivalent to Logger.Println when build.DEBUG is true. Otherwise it is a no-op.

func (*Logger) Severe added in v1.0.3

func (l *Logger) Severe(v ...interface{})

Severe logs a message with a SEVERE prefix. If debug mode is enabled, it will also write the message to os.Stderr and panic. Severe should be called if there is a severe problem with the user's machine or setup that should be addressed ASAP but does not necessarily require that the machine crash or exit.

type Metadata added in v0.3.3

type Metadata struct {
	Header, Version string
}

Metadata contains the header and version of the data being stored.

Jump to

Keyboard shortcuts

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