Documentation
¶
Index ¶
- Variables
- func Load(meta Metadata, data interface{}, r io.Reader) error
- func LoadFile(meta Metadata, data interface{}, filename string) error
- func NewSafeFile(filename string) (*safeFile, error)
- func RandomSuffix() string
- func Save(meta Metadata, data interface{}, w io.Writer) error
- func SaveFile(meta Metadata, data interface{}, filename string) error
- func SaveFileSync(meta Metadata, data interface{}, filename string) error
- type BoltDatabase
- type Logger
- type Metadata
Constants ¶
This section is empty.
Variables ¶
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 NewSafeFile ¶
NewSafeFile returns a file that can atomically be written to disk, minimizing the risk of corruption.
func RandomSuffix ¶
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 SaveFileSync ¶
SaveFileSync atomically saves json data to a file and then syncs to disk.
Types ¶
type BoltDatabase ¶
BoltDatabase is a persist-level wrapper for the bolt database, providing extra information such as a version number.
func OpenDatabase ¶
func OpenDatabase(md Metadata, filename string) (*BoltDatabase, error)
OpenDatabase opens a database and validates its metadata.
type Logger ¶
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 ¶
NewFileLogger returns a logger that logs to logFilename. The file is opened in append mode, and created if it does not exist.
func NewLogger ¶
NewLogger returns a logger that can be closed. Calls should not be made to the logger after 'Close' has been called.
func (*Logger) Close ¶
Close logs a shutdown message and closes the Logger's underlying io.Writer, if it is also an io.Closer.
func (*Logger) Critical ¶
func (l *Logger) Critical(v ...interface{})
Critical logs a message with a CRITICAL prefix. If debug mode is enabled, it will also write the message to os.Stderr and panic.
func (*Logger) Debug ¶
func (l *Logger) Debug(v ...interface{})
Debug is equivalent to Logger.Print when build.DEBUG is true. Otherwise it is a no-op.