caddyconfig

package
v2.0.0-beta.15 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: Apache-2.0 Imports: 2 Imported by: 253

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON

func JSON(val interface{}, warnings *[]Warning) json.RawMessage

JSON encodes val as JSON, returning it as a json.RawMessage. Any marshaling errors (which are highly unlikely with correct code) are converted to warnings. This is convenient when filling config structs that require a json.RawMessage, without having to worry about errors.

func JSONIndent

func JSONIndent(val interface{}) ([]byte, error)

JSONIndent is used to JSON-marshal the final resulting Caddy configuration in a consistent, human-readable way.

func JSONModuleObject

func JSONModuleObject(val interface{}, fieldName, fieldVal string, warnings *[]Warning) json.RawMessage

JSONModuleObject is like JSON, except it marshals val into a JSON object and then adds a key to that object named fieldName with the value fieldVal. This is useful for JSON-encoding module values where the module name has to be described within the object by a certain key; for example, "responder": "file_server" for a file server HTTP responder. The val must encode into a map[string]interface{} (i.e. it must be a struct or map), and any errors are converted into warnings, so this can be conveniently used when filling a struct. For correct code, there should be no errors.

func RegisterAdapter

func RegisterAdapter(name string, adapter Adapter) error

RegisterAdapter registers a config adapter with the given name. This should usually be done at init-time.

Types

type Adapter

type Adapter interface {
	Adapt(body []byte, options map[string]interface{}) ([]byte, []Warning, error)
}

Adapter is a type which can adapt a configuration to Caddy JSON. It returns the results and any warnings, or an error.

func GetAdapter

func GetAdapter(name string) Adapter

GetAdapter returns the adapter with the given name, or nil if one with that name is not registered.

type Warning

type Warning struct {
	File      string `json:"file,omitempty"`
	Line      int    `json:"line,omitempty"`
	Directive string `json:"directive,omitempty"`
	Message   string `json:"message,omitempty"`
}

Warning represents a warning or notice related to conversion.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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