parser

package module
v0.0.0-...-3abfa3d Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2025 License: MIT Imports: 10 Imported by: 0

README

parser

A file parser tool, now supported toml configuration file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte, ext string, v any) error

Decode decodes the contents of data into a pointer v. ext is the file extension for the format of data, which must be one of the following: toml, yaml or json. The last target of v pointed to must be a struct, map or empty interface. If no error occurs, v will be filled with the decoded data.

The process can be roughly divided into four steps: 1. Call function from different dependency packages to decode the data into a map[string]any value. 2. Build a tree of nodes from the top down, these nodes contain only value. 3. Assign metadata such as actual type to these nodes depending on the type of target. 4. Fill value to v depending on the metadata and value from nodes.

During the process, if occurs an empty interface that actual type cannot be determined, then treated it as a string.

func DecodeFile

func DecodeFile(path string, v any) error

DecodeFile decodes the contents of given file into a pointer v.

See Decode function for a description of decoding process.

Types

This section is empty.

Jump to

Keyboard shortcuts

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