file

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package file loads configuration from OS file.

File loads a file with the given path from the OS file system and returns a nested map[string]any that is parsed with the given unmarshal function.

The unmarshal function must be able to unmarshal the file content into a map[string]any. For example, with the default json.Unmarshal, the file is parsed as JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

File is a Provider that loads configuration from a OS file.

To create a new File, call New.

func New

func New(path string, opts ...Option) *File

New creates a File with the given path and Option(s).

func (*File) Load

func (f *File) Load() (map[string]any, error)

func (*File) Status added in v0.8.0

func (f *File) Status(onStatus func(bool, error))

func (*File) String

func (f *File) String() string

func (*File) Watch

func (f *File) Watch(ctx context.Context, onChange func(map[string]any)) (err error)

type Option

type Option func(options *options)

Option configures the a File with specific options.

func WithUnmarshal

func WithUnmarshal(unmarshal func([]byte, any) error) Option

WithUnmarshal provides the function used to parses the configuration file. The unmarshal function must be able to unmarshal the file content into a map[string]any.

The default function is json.Unmarshal.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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