parser

package
v1.0.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 29 Imported by: 1 module, 0 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

View Source
const (
	File       = "file"
	Yaml       = "yaml"
	Properties = "properties"
	Ini        = "ini"
	Json       = "json"
	Xml        = "xml"
	Toml       = "toml"
)

The file parsing options that are available for a server configuration file.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigFile

type ConfigFile interface {
	io.Reader
	io.Writer
	io.Seeker
	Name() string
	Stat() (os.FileInfo, error)
	Truncate(size int64) error
}

ConfigFile is the handle to a configuration file that is parsed and then rewritten in place. It is satisfied by both *os.File and filesystem.File.

type ConfigurationFile

type ConfigurationFile struct {
	FileName        string                         `json:"file"`
	Parser          ConfigurationParser            `json:"parser"`
	Replace         []ConfigurationFileReplacement `json:"replace"`
	AllowCreateFile bool                           `json:"create_file"` // assumed true by unmarshal as it was the original behaviour
	// contains filtered or unexported fields
}

ConfigurationFile defines a configuration file for the server startup. These will be looped over and modified before the server finishes booting.

func (*ConfigurationFile) IterateOverJson

func (f *ConfigurationFile) IterateOverJson(data []byte) ([]byte, error)

Iterate over an unstructured JSON/YAML/etc. interface and set all of the required key/value pairs for the configuration file.

We need to support wildcard characters in key searches, this allows you to make modifications to multiple keys at once, especially useful for games with multiple configurations per-world (such as Spigot and Bungeecord) where we'll need to make adjustments to the bind address for the user.

This does not currently support nested wildcard matches. For example, foo.*.bar will work, however foo.*.bar.*.baz will not, since we'll only be splitting at the first wildcard, and not subsequent ones.

func (*ConfigurationFile) LookupConfigurationValue

func (f *ConfigurationFile) LookupConfigurationValue(cfr ConfigurationFileReplacement) (result string, err error)

Looks up a configuration value on the Daemon given a dot-notated syntax.

func (*ConfigurationFile) Parse

func (f *ConfigurationFile) Parse(file ConfigFile) error

Parse parses a given configuration file and updates all the values within as defined in the API response from the Panel.

func (*ConfigurationFile) UnmarshalJSON

func (f *ConfigurationFile) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom unmarshaler for configuration files. A replacement that fails to decode doesn't fail the entire operation: it is logged so someone can find the issue and skipped, and the other replacements are kept.

func (*ConfigurationFile) UnmarshalJSONFrom

func (f *ConfigurationFile) UnmarshalJSONFrom(dec *jsontext.Decoder) error

UnmarshalJSONFrom decodes a configuration file in a single pass. A key whose value is null is treated as missing.

type ConfigurationFileReplacement

type ConfigurationFileReplacement struct {
	Match       string       `json:"match"`
	IfValue     string       `json:"if_value"`
	ReplaceWith ReplaceValue `json:"replace_with"`
}

ConfigurationFileReplacement defines a single find/replace instance for a given server configuration file.

func (*ConfigurationFileReplacement) UnmarshalJSON

func (cfr *ConfigurationFileReplacement) UnmarshalJSON(data []byte) error

UnmarshalJSON handles unmarshaling the JSON representation into a struct that provides more useful data to this functionality.

func (*ConfigurationFileReplacement) UnmarshalJSONFrom

func (cfr *ConfigurationFileReplacement) UnmarshalJSONFrom(dec *jsontext.Decoder) error

UnmarshalJSONFrom decodes a single replacement in one pass. "match" and "replace_with" are required; "if_value" is optional. Eggs that predate "replace_with" use the old "value" key, which is accepted as a fallback.

type ConfigurationParser

type ConfigurationParser string

func (ConfigurationParser) String

func (cp ConfigurationParser) String() string

type ReplaceValue

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

func (*ReplaceValue) Bytes

func (cv *ReplaceValue) Bytes() []byte

func (*ReplaceValue) String

func (cv *ReplaceValue) String() string

String returns the value as a string representation.

func (*ReplaceValue) Type

func (cv *ReplaceValue) Type() ValueType

Type returns the underlying data type for the Value field.

func (*ReplaceValue) Value

func (cv *ReplaceValue) Value() []byte

Value returns the underlying value of the replacement. Strings are already unescaped, so a section sign sent as a JSON escape comes back as "§Foo". Other types are returned as their raw JSON text.

type ValueType

type ValueType int

ValueType is the JSON type of a replacement value as written in the egg.

const (
	InvalidValue ValueType = iota
	StringValue
	NumberValue
	BooleanValue
	NullValue
	ObjectValue
	ArrayValue
)

Jump to

Keyboard shortcuts

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