parse

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 5 Imported by: 17 modules, 24 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Array:        true,
	Object:       true,
	StringDQuote: true,
	StringSQuote: true,
}

DefaultConfig is the default config with all parser features enabled.

View Source
var EnvConfig = Config{
	Array:        true,
	Object:       false,
	StringDQuote: true,
	StringSQuote: true,
}

EnvConfig is configuration for parser when the value comes from environmental variable.

View Source
var NoopConfig = Config{
	Array:        false,
	Object:       false,
	StringDQuote: false,
	StringSQuote: false,
	IgnoreCommas: true,
}

NoopConfig is configuration for parser that disables all options.

Functions

func Value

func Value(content string) (interface{}, error)

Value parses command line arguments, supporting boolean, numbers, strings, arrays, objects.

The parser implements a superset of JSON, but only a subset of YAML by allowing for arrays and objects having a trailing comma. In addition 3 string types are supported:

  1. single quoted string (no unescaping of any characters)
  2. double quoted strings (characters are escaped)
  3. strings without quotes. String parsing stops at special characters like '[]{},:'

In addition, top-level values can be separated by ',' to build arrays without having to use [].

func ValueWithConfig

func ValueWithConfig(content string, cfg Config) (interface{}, error)

ValueWithConfig parses command line arguments, supporting boolean, numbers, strings, arrays, objects when enabled.

The parser implements a superset of JSON, but only a subset of YAML by allowing for arrays and objects having a trailing comma. In addition 3 string types are supported:

  1. single quoted string (no unescaping of any characters)
  2. double quoted strings (characters are escaped)
  3. strings without quotes. String parsing stops at special characters like '[]{},:'

In addition, top-level values can be separated by ',' to build arrays without having to use [].

Types

type Config

type Config struct {
	// Enables parsing arrays from values enclosed in [].
	Array bool
	// Enables parsing objects enclosed in {}.
	Object bool
	// Enables parsing double quoted strings, where values are escaped.
	StringDQuote bool
	// Enables parsing single quotes strings, where no values are escaped.
	StringSQuote bool
	// Enables ignoring commas as a shortcut for building arrays: a,b parses to [a,b].
	// The comma array syntax is enabled by default for backwards compatibility.
	IgnoreCommas bool
}

Config allows enabling and disabling parser features.

Jump to

Keyboard shortcuts

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