jsonfile

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFieldNotFound parameter not found into json.
	ErrFieldNotFound = errors.New("JSON field not found")

	// ErrInvalidValueType invalid value type.
	ErrInvalidValueType = errors.New("invalid value type")

	// ErrInvalidURL invalid file URL.
	ErrInvalidURL = errors.New("invalid file URL")
)

Functions

This section is empty.

Types

type JSONFile

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

JSONFile represents the JSON file and also implements the io.write interface, saving directly to the file.

func FromPath

func FromPath(path string) (*JSONFile, error)

FromPath parses a JSONFile object from path.

func FromURL

func FromURL(ctx context.Context, url, destPath, tarballFileName string) (*JSONFile, error)

FromURL fetches the file from the given URL and returns its content. If tarballFileName is not empty, the URL is interpreted as a tarball file, tarballFileName is extracted from it and is returned instead of the URL content.

func New

func New(file ReadWriteSeeker) *JSONFile

New creates a new JSONFile.

func (*JSONFile) Bytes

func (f *JSONFile) Bytes() ([]byte, error)

Bytes returns the jsonfile byte array.

func (*JSONFile) Close

func (f *JSONFile) Close() error

Close the file.

func (*JSONFile) Field

func (f *JSONFile) Field(key string, param interface{}) error

Field returns the param by key and the position into byte slice from the file reader. Key can be a path to a nested parameters eg: app_state.staking.accounts.

func (*JSONFile) Hash

func (f *JSONFile) Hash() (string, error)

Hash returns the hash of the file.

func (*JSONFile) Reset

func (f *JSONFile) Reset() error

Reset sets the offset for the next Read or Write to 0.

func (*JSONFile) String

func (f *JSONFile) String() (string, error)

String returns the file string.

func (*JSONFile) TarballPath

func (f *JSONFile) TarballPath() string

TarballPath returns the tarball path.

func (*JSONFile) URL

func (f *JSONFile) URL() string

URL returns the genesis URL.

func (*JSONFile) Update

func (f *JSONFile) Update(opts ...UpdateFileOption) error

Update updates the file with the new parameters by key.

func (*JSONFile) Write

func (f *JSONFile) Write(p []byte) (int, error)

Write implement the write method for io.Writer interface.

type ReadWriteSeeker

type ReadWriteSeeker interface {
	io.ReadWriteSeeker
	Close() error
	Sync() error
}

ReadWriteSeeker represents the owns ReadWriteSeeker interface inherit from io.ReadWriteSeeker.

type UpdateFileOption

type UpdateFileOption func(map[string][]byte)

UpdateFileOption configures file update function with key and value.

func WithKeyValue

func WithKeyValue(key string, value string) UpdateFileOption

WithKeyValue updates a file value object by key.

func WithKeyValueByte added in v0.26.0

func WithKeyValueByte(key string, value []byte) UpdateFileOption

WithKeyValueByte updates a file byte value object by key.

func WithKeyValueInt

func WithKeyValueInt(key string, value int64) UpdateFileOption

WithKeyValueInt updates a file int value object by key.

func WithKeyValueTimestamp

func WithKeyValueTimestamp(key string, t int64) UpdateFileOption

WithKeyValueTimestamp updates a time value.

func WithKeyValueUint

func WithKeyValueUint(key string, value uint64) UpdateFileOption

WithKeyValueUint updates a file uint value object by key.

Jump to

Keyboard shortcuts

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