parse

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

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,
}

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 {
	Array        bool
	Object       bool
	StringDQuote bool
	StringSQuote 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