config

package
v3.9.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithConfig

func ContextWithConfig(ctx context.Context, cfg *Config) context.Context

ContextWithConfig returns a new context with a reference to the config.

func ParseSourceURL

func ParseSourceURL(value string) (*url.URL, error)

ParseSourceURL parses a datasource URL value, which may be '-' (for stdin://), or it may be a Windows path (with driver letter and back-slack separators) or UNC, or it may be relative. It also might just be a regular absolute URL... In all cases it returns a correct URL for the value.

Types

type Config

type Config struct {
	Stdin  io.Reader `yaml:"-"`
	Stdout io.Writer `yaml:"-"`
	Stderr io.Writer `yaml:"-"`

	// internal use only, can't be injected in YAML
	PostExecInput io.Reader `yaml:"-"`

	Input       string   `yaml:"in,omitempty"`
	InputDir    string   `yaml:"inputDir,omitempty"`
	InputFiles  []string `yaml:"inputFiles,omitempty,flow"`
	ExcludeGlob []string `yaml:"excludes,omitempty"`

	OutputDir   string   `yaml:"outputDir,omitempty"`
	OutputMap   string   `yaml:"outputMap,omitempty"`
	OutputFiles []string `yaml:"outputFiles,omitempty,flow"`
	OutMode     string   `yaml:"chmod,omitempty"`

	LDelim string `yaml:"leftDelim,omitempty"`
	RDelim string `yaml:"rightDelim,omitempty"`

	PostExec []string `yaml:"postExec,omitempty,flow"`

	DataSources map[string]DataSource `yaml:"datasources,omitempty"`
	Context     map[string]DataSource `yaml:"context,omitempty"`
	Plugins     map[string]string     `yaml:"plugins,omitempty"`

	// Extra HTTP headers not attached to pre-defined datsources. Potentially
	// used by datasources defined in the template.
	ExtraHeaders map[string]http.Header `yaml:"-"`

	Templates []string `yaml:"templates,omitempty"`

	PluginTimeout time.Duration `yaml:"pluginTimeout,omitempty"`

	ExecPipe      bool `yaml:"execPipe,omitempty"`
	SuppressEmpty bool `yaml:"suppressEmpty,omitempty"`
	Experimental  bool `yaml:"experimental,omitempty"`
}

Config - configures the gomplate execution

func FromContext

func FromContext(ctx context.Context) (cfg *Config)

FromContext returns a config from the given context, if any. If no config is present a new default configuration will be returned.

func Parse

func Parse(in io.Reader) (*Config, error)

Parse a config file

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults - any defaults changed here should be added to cmd.InitFlags as well for proper help/usage display.

func (*Config) GetMode

func (c *Config) GetMode() (os.FileMode, bool, error)

GetMode - parse an os.FileMode out of the string, and let us know if it's an override or not...

func (*Config) MergeFrom

func (c *Config) MergeFrom(o *Config) *Config

MergeFrom - use this Config as the defaults, and override it with any non-zero values from the other Config

Note that Input/InputDir/InputFiles will override each other, as well as OutputDir/OutputFiles.

func (*Config) ParseDataSourceFlags

func (c *Config) ParseDataSourceFlags(datasources, contexts, headers []string) error

ParseDataSourceFlags - sets the DataSources and Context fields from the key=value format flags as provided at the command-line

func (*Config) ParsePluginFlags

func (c *Config) ParsePluginFlags(plugins []string) error

ParsePluginFlags - sets the Plugins field from the key=value format flags as provided at the command-line

func (*Config) String

func (c *Config) String() string

String -

func (Config) Validate

func (c Config) Validate() (err error)

Validate the Config

type DataSource

type DataSource struct {
	URL    *url.URL    `yaml:"-"`
	Header http.Header `yaml:"header,omitempty,flow"`
}

DataSource - datasource configuration

func (DataSource) MarshalYAML

func (d DataSource) MarshalYAML() (interface{}, error)

MarshalYAML - satisfy the yaml.Marshaler interface - URLs aren't well supported, and anyway we need to do some extra parsing

func (*DataSource) UnmarshalYAML

func (d *DataSource) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML - satisfy the yaml.Umarshaler interface - URLs aren't well supported, and anyway we need to do some extra parsing

Jump to

Keyboard shortcuts

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