jsonfile

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: ISC Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("json file not found")

Functions

func Exists

func Exists(fname string) bool

Exists returns true if the specified file exists.

func Read

func Read(fname string, data interface{}) error

Read the first json message from the given filename and decodes it into data.

func RemoveIfExists

func RemoveIfExists(fname string) error

RemoveIfExists removes the filename if it exists. If it does not exist, this doesn't return an error.

func Write

func Write(fname string, data interface{}, log slog.Logger) error

Write data to a temp file, then renames the temp file to the passed filename in json format.

log is used to log warnings that are not fatal to the Write() operation.

Types

type MatchedNumberedFile

type MatchedNumberedFile struct {
	Filename string
	ID       uint64
}

MatchedNumberedFile is a matched numbered file.

type NumberedFilePattern

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

NumberedFilePattern can be used to match files in a dir.

func MakeDecimalFilePattern

func MakeDecimalFilePattern(prefix, suffix string, isDir bool) NumberedFilePattern

MakeDecimalFilePattern creates a numbered file pattern that uses decimal encoded numbers. It panics if prefix+suffix cannot be made into a valid regexp.

func MakeHexFilePattern

func MakeHexFilePattern(prefix, suffix string, isDir bool) NumberedFilePattern

MakeHexFilePattern creates a numbered file pattern that can handle hex encoded numbers. It panics if prefix+suffix cannot be made into a valid regexp.

func (NumberedFilePattern) FilenameFor

func (nfp NumberedFilePattern) FilenameFor(i uint64) string

FilenameFor returns the filename for a given number.

func (NumberedFilePattern) Last

Last returns the number and filename of the file with highest number in the dir.

If no file is found, the returned filename is empty.

func (NumberedFilePattern) MatchFiles

func (nfp NumberedFilePattern) MatchFiles(dir string) ([]MatchedNumberedFile, error)

MatchFiles returns the files that match the pattern in the given dir.

func (NumberedFilePattern) NextFilename added in v0.1.9

func (nfp NumberedFilePattern) NextFilename(dir string) (string, uint64, error)

NextFilename returns the next filename and ID for numbered files inside the given dir.

Jump to

Keyboard shortcuts

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