file

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: MIT Imports: 10 Imported by: 5

README

File

Load and save file with TOML, JSON, YAML codecs.

go get github.com/rytsh/liz/file

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Codec map[string]Codec
}

func New

func New() *API

func (*API) Load

func (a *API) Load(path string, dst interface{}) error

func (*API) LoadContent

func (a *API) LoadContent(v []byte, dst interface{}, codec Codec) error

func (*API) LoadRaw

func (a *API) LoadRaw(path string) ([]byte, error)

func (*API) LoadWithCodec added in v0.1.1

func (a *API) LoadWithCodec(path string, dst interface{}, codec Codec) error

LoadWithCodec loads the file with the specified codec.

If the codec is nil, the codec is determined by the file extension.

func (*API) LoadWithReturn added in v0.1.2

func (a *API) LoadWithReturn(path string, codec Codec) (any, error)

LoadWithReturn loads the file with the specified codec and returns the result.

func (*API) OpenFile added in v0.1.3

func (a *API) OpenFile(path string, opts ...Option) (*os.File, error)

Open opens a file with options.

func (*API) SetRaw

func (a *API) SetRaw(path string, data []byte, opts ...Option) error

func (*API) SetRawWithReader added in v0.1.4

func (a *API) SetRawWithReader(path string, data io.Reader, opts ...Option) error

func (*API) SetWithCodec

func (a *API) SetWithCodec(path string, data any, opts ...Option) error

type Codec

type Codec interface {
	Encode(w io.Writer, v any) error
	Decode(r io.Reader, v interface{}) error
}

type JSON

type JSON struct {
	Indent string
}

JSON is a codec for JSON file.

func (JSON) Decode

func (JSON) Decode(r io.Reader, v interface{}) error

func (JSON) Encode

func (j JSON) Encode(w io.Writer, v any) error

type Option

type Option func(options *options) error

func WithFilePerm

func WithFilePerm(filePerm string) Option

WithFilePerm sets the file permission.

The permission is a string of octal digits, such as "0644".

func WithFolderPerm

func WithFolderPerm(folderPerm string) Option

WithFolderPerm sets the folder permission.

The permission is a string of octal digits, such as "0755".

type RAW added in v0.1.1

type RAW struct{}

func (RAW) Decode added in v0.1.1

func (RAW) Decode(r io.Reader, v any) error

func (RAW) Encode added in v0.1.1

func (RAW) Encode(w io.Writer, v any) error

type TOML

type TOML struct{}

TOML is a codec for TOML file.

func (TOML) Decode

func (TOML) Decode(r io.Reader, v interface{}) error

func (TOML) Encode

func (TOML) Encode(w io.Writer, v any) error

type YAML

type YAML struct{}

YAML is a codec for YAML file.

func (YAML) Decode

func (YAML) Decode(r io.Reader, v interface{}) error

func (YAML) Encode

func (YAML) Encode(w io.Writer, v any) error

Jump to

Keyboard shortcuts

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