file

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package file contains utility functions for interacting with files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

type Parser interface {
	Parse(b []byte) (interface{}, error)
}

Parser converts a slice of bytes into an object.

type ParserFunc

type ParserFunc func(b []byte) (interface{}, error)

ParserFunc is a convenience type for using typical Go parsers as the Parser type in this package.

func (ParserFunc) Parse

func (f ParserFunc) Parse(b []byte) (interface{}, error)

type PeriodicView

type PeriodicView struct {
	// ReadInterval is the duration between re-reads from disk.
	ReadInterval time.Duration

	// Path to the file to read.
	Path string

	// Parser is used to construct the cached object whenever the View re-reads different
	// contents from the file. If nil, the object isn't parsed and the bytes are returned
	// as-is.
	Parser Parser
	// contains filtered or unexported fields
}

PeriodicView is a View implementation that periodically re-reads file contents from disk and then parses them into an object.

To free up resources used by the PeriodicView, call Close. Calling Get after Close will return an error.

It is not safe to change PeriodicView fields after the first call to Get.

func (*PeriodicView) Close

func (v *PeriodicView) Close() error

Close cleans up the internal resources used to maintain the PeriodicView.

Calling Close more than once is a no-op.

func (*PeriodicView) Get

func (v *PeriodicView) Get() (interface{}, error)

type View

type View interface {
	// Get returns a reference to the cached object. Get is safe for concurrent use.
	//
	// Get guarantees that once an object is returned, it will no longer be modified by
	// View internals.
	//
	// However, Get implementations are free to return different objects or
	// return references to the same object, so callers should not assume
	// they see the same object across different calls.
	Get() (interface{}, error)
}

View maintains a cached concurrency-safe view of an object.

Use Get to get a reference to the object.

Jump to

Keyboard shortcuts

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