parser

package
v0.0.0-...-eb3c7bf Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

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

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

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigurationFile

type ConfigurationFile struct {
	FileName string                         `json:"file"`
	Parser   ConfigurationParser            `json:"parser"`
	Replace  []ConfigurationFileReplacement `json:"replace"`
	// 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) (*gabs.Container, 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) (string, error)

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

func (*ConfigurationFile) Parse

func (f *ConfigurationFile) Parse(file ufs.File) 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. If there is an error while parsing out the replacements, don't fail the entire operation, just log a global warning so someone can find the issue, and return an empty array of replacements.

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) SetAtPathway

func (cfr *ConfigurationFileReplacement) SetAtPathway(c *gabs.Container, path string, value string) error

Sets the value at a specific pathway, but checks if we were looking for a specific value or not before doing it.

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.

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. This will automatically handle casting the UTF-8 sequence into the expected value, switching something like "\u00a7Foo" into "§Foo".

func (*ReplaceValue) Type

func (cv *ReplaceValue) Type() jsonparser.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. Be aware that this can include escaped UTF-8 sequences that will need to be handled by the caller in order to avoid accidentally injecting invalid sequences into the running process.

For example the expected value may be "§Foo" but you'll be working directly with "\u00a7FOo" for this value. This will cause user pain if not solved since that is clearly not the value they were expecting to be using.

Jump to

Keyboard shortcuts

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