config

package
v0.4.16 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvaluateConfigEntry added in v0.4.9

func EvaluateConfigEntry(node interface{}) (interface{}, error)

EvaluateConfigEntry takes a node which can be either a string, or a map with a key `env` and a string value. If the node is a string, it is returned as is. If the node is a map, it is evaluated recursively. If the map has a single key named `_env`, the entire map is replaced with the environment value corresponding to `_env`. If it is a list, it is evaluated recursively.

func NewHandlerParametersFromLayerParams added in v0.4.6

func NewHandlerParametersFromLayerParams(p *LayerParams)

NewHandlerParametersFromLayerParams creates a new HandlerParameters from the config file. It currently requires a list of layerDefinitions in order to lookup the correct layers to stored as ParsedParameterLayer. It doesn't fail if configured layers don't exist.

TODO(manuel, 2023-05-31) Add a way to validate the fact that overrides in a config file might have a typo and don't correspond to existing layer definitions in the application.

Types

type Command

type Command struct {
	File         string `yaml:"file"`
	TemplateName string `yaml:"templateName"`

	TemplateLookup *TemplateLookupConfig `yaml:"templateLookup,omitempty"`

	AdditionalData map[string]interface{} `yaml:"additionalData,omitempty"`
	Defaults       *LayerParams           `yaml:"defaults,omitempty"`
	Overrides      *LayerParams           `yaml:"overrides,omitempty"`

	Stream *bool `yaml:"stream,omitempty"`
}

func (*Command) ExpandPaths

func (c *Command) ExpandPaths() error

type CommandDir

type CommandDir struct {
	Repositories               []string `yaml:"repositories"`
	IncludeDefaultRepositories *bool    `yaml:"includeDefaultRepositories"`

	TemplateLookup *TemplateLookupConfig `yaml:"templateLookup,omitempty"`

	TemplateName      string `yaml:"templateName,omitempty"`
	IndexTemplateName string `yaml:"indexTemplateName,omitempty"`

	AdditionalData map[string]interface{} `yaml:"additionalData,omitempty"`
	Defaults       *LayerParams           `yaml:"defaults,omitempty"`
	Overrides      *LayerParams           `yaml:"overrides,omitempty"`
	BlackList      *LayerFlagNames        `yaml:"blackList,omitempty"`
	WhiteList      *LayerFlagNames        `yaml:"whiteList,omitempty"`

	Stream *bool `yaml:"stream,omitempty"`
}

CommandDir represents the config file entry for a command directory route.

func (*CommandDir) ExpandPaths

func (c *CommandDir) ExpandPaths() error

type Config

type Config struct {
	Routes   []*Route  `yaml:"routes"`
	Defaults *Defaults `yaml:"defaults,omitempty"`
}

func ParseConfig

func ParseConfig(data []byte) (*Config, error)

func (*Config) Initialize added in v0.3.2

func (cfg *Config) Initialize() error

type DefaultRendererOptions added in v0.3.2

type DefaultRendererOptions struct {
	UseDefaultParkaRenderer *bool `yaml:"useDefaultParkaRenderer,omitempty"`
	// TODO(manuel, 2023-06-21) These two options are not implemented yet
	// It is not so much that they are hard to implement, but rather that they are annoying to test.
	// See: https://github.com/go-go-golems/parka/issues/56
	TemplateDirectory        string `yaml:"templateDirectory,omitempty"`
	MarkdownBaseTemplateName string `yaml:"markdownBaseTemplateName,omitempty"`
}

DefaultRendererOptions controls the default renderer. If UseDefaultParkaRenderer is true, the default parka renderer will be used. It renders markdown files using base.tmpl.html and uses a tailwind css stylesheet which has to be served under dist/output.css.

type Defaults added in v0.3.2

type Defaults struct {
	Renderer            *DefaultRendererOptions `yaml:"renderer,omitempty"`
	UseParkaStaticFiles *bool                   `yaml:"useParkaStaticFiles,omitempty"`
}

Defaults controls the default renderer and which embedded static files to serve.

type EnvEvaluator added in v0.4.9

type EnvEvaluator struct{}

func (*EnvEvaluator) Evaluate added in v0.4.9

func (e *EnvEvaluator) Evaluate(node interface{}) (interface{}, bool, error)

type Evaluator added in v0.4.9

type Evaluator interface {
	// Evaluate takes a node and evaluates it.
	// If it succeeds, it returns the evaluated node, and true.
	// If it fails, it returns nil, false, and an error.
	// This would mean passing the value to the next evaluator down the chain.
	Evaluate(node interface{}) (interface{}, bool, error)
}

type HandlerParameters added in v0.4.6

type HandlerParameters struct {
	Layers    map[string]map[string]interface{}
	Flags     map[string]interface{}
	Arguments map[string]interface{}
}

func NewHandlerParameters added in v0.4.6

func NewHandlerParameters() *HandlerParameters

func (*HandlerParameters) Merge added in v0.4.6

func (ho *HandlerParameters) Merge(other *HandlerParameters)

Merge merges the given overrides into this one. If a layer is already present, it is merged with the given one. Flags and arguments are merged, overrides taking precedence.

type LayerFlagNames added in v0.4.8

type LayerFlagNames struct {
	Layers      []string            `yaml:"layers,omitempty"`
	LayerParams map[string][]string `yaml:"layerParams,omitempty"`
	Flags       []string            `yaml:"flags,omitempty"`
	Arguments   []string            `yaml:"arguments,omitempty"`
}

type LayerParams

type LayerParams struct {
	Layers    map[string]map[string]interface{} `yaml:"layers,omitempty"`
	Flags     map[string]interface{}            `yaml:"flags,omitempty"`
	Arguments map[string]interface{}            `yaml:"arguments,omitempty"`
}

func NewLayerParams

func NewLayerParams() *LayerParams

func (*LayerParams) Merge

func (p *LayerParams) Merge(overrides *LayerParams)

Merge merges the two LayerParams, with the overrides taking precedence. It merges all the layers, flags, and arguments. For each layer, the layer flags are merged as well, overrides taking precedence.

type OverridesAndDefaults added in v0.4.6

type OverridesAndDefaults struct {
	Overrides *HandlerParameters
	Defaults  *HandlerParameters
}

func (*OverridesAndDefaults) ComputeParserOptions added in v0.4.6

func (od *OverridesAndDefaults) ComputeParserOptions(stream bool) []parser.ParserOption

type OverridesAndDefaultsOption added in v0.4.6

type OverridesAndDefaultsOption func(*OverridesAndDefaults)

func WithDefaultArgument added in v0.4.6

func WithDefaultArgument(name string, value string) OverridesAndDefaultsOption

func WithDefaultFlag added in v0.4.6

func WithDefaultFlag(name string, value string) OverridesAndDefaultsOption

func WithLayerDefaults added in v0.4.6

func WithLayerDefaults(name string, layer map[string]interface{}) OverridesAndDefaultsOption

WithLayerDefaults populates the defaults for the given layer. If a value is already set, the value is skipped.

func WithMergeDefaultLayer added in v0.4.6

func WithMergeDefaultLayer(name string, layer *layers.ParsedParameterLayer) OverridesAndDefaultsOption

func WithMergeDefaults added in v0.4.6

func WithMergeDefaults(defaults *HandlerParameters) OverridesAndDefaultsOption

func WithMergeOverrideLayer added in v0.4.6

func WithMergeOverrideLayer(name string, layer map[string]interface{}) OverridesAndDefaultsOption

func WithMergeOverrides added in v0.4.6

func WithMergeOverrides(overrides *HandlerParameters) OverridesAndDefaultsOption

func WithOverrideArgument added in v0.4.6

func WithOverrideArgument(name string, value string) OverridesAndDefaultsOption

func WithOverrideFlag added in v0.4.6

func WithOverrideFlag(name string, value string) OverridesAndDefaultsOption

func WithReplaceDefaultLayer added in v0.4.6

func WithReplaceDefaultLayer(name string, layer map[string]interface{}) OverridesAndDefaultsOption

func WithReplaceDefaults added in v0.4.6

func WithReplaceDefaults(defaults *HandlerParameters) OverridesAndDefaultsOption

func WithReplaceOverrideLayer added in v0.4.6

func WithReplaceOverrideLayer(name string, layer map[string]interface{}) OverridesAndDefaultsOption

func WithReplaceOverrides added in v0.4.6

func WithReplaceOverrides(overrides *HandlerParameters) OverridesAndDefaultsOption

type Route

type Route struct {
	Path              string       `yaml:"path"`
	CommandDirectory  *CommandDir  `yaml:"commandDirectory,omitempty"`
	Command           *Command     `yaml:"command,omitempty"`
	Static            *Static      `yaml:"static,omitempty"`
	StaticFile        *StaticFile  `yaml:"staticFile,omitempty"`
	TemplateDirectory *TemplateDir `yaml:"templateDirectory,omitempty"`
	Template          *Template    `yaml:"template,omitempty"`
}

Route represents a single sub-route of the server. Only one of the booleans or one of the pointers should be true or non-nil. This is the first attempt at the structure of a config file, and is bound to change.

func (*Route) HandlesCommand

func (r *Route) HandlesCommand() bool

func (*Route) HandlesStatic

func (r *Route) HandlesStatic() bool

func (*Route) HandlesTemplate

func (r *Route) HandlesTemplate() bool

func (*Route) IsCommandDirRoute

func (r *Route) IsCommandDirRoute() bool

func (*Route) IsCommandRoute

func (r *Route) IsCommandRoute() bool

func (*Route) IsStaticFileRoute

func (r *Route) IsStaticFileRoute() bool

func (*Route) IsStaticRoute

func (r *Route) IsStaticRoute() bool

func (*Route) IsTemplateDirRoute

func (r *Route) IsTemplateDirRoute() bool

func (*Route) IsTemplateRoute

func (r *Route) IsTemplateRoute() bool

type RouteHandlerConfiguration

type RouteHandlerConfiguration interface {
	//
	ExpandPaths() error
}

RouteHandlerConfiguration is the interface that all route handler configurations must implement. By RouteHandlerConfiguration, we mean things like CommandDir, Command, Static, etc...

type SsmEvaluator added in v0.4.9

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

func NewSsmEvaluator added in v0.4.9

func NewSsmEvaluator(ctx context.Context) (*SsmEvaluator, error)

func (*SsmEvaluator) Evaluate added in v0.4.9

func (s *SsmEvaluator) Evaluate(node interface{}) (interface{}, bool, error)

type Static

type Static struct {
	LocalPath string `yaml:"localPath"`
}

func (*Static) ExpandPaths

func (s *Static) ExpandPaths() error

type StaticFile

type StaticFile struct {
	LocalPath string `yaml:"localPath"`
}

func (*StaticFile) ExpandPaths

func (s *StaticFile) ExpandPaths() error

type Template

type Template struct {
	// every request will be rendered from the template file, using the default renderer in the case of markdown
	// content.
	TemplateFile   string                 `yaml:"templateFile"`
	AdditionalData map[string]interface{} `yaml:"additionalData,omitempty"`
}

func (*Template) ExpandPaths

func (t *Template) ExpandPaths() error

type TemplateDir

type TemplateDir struct {
	LocalDirectory    string                 `yaml:"localDirectory"`
	IndexTemplateName string                 `yaml:"indexTemplateName,omitempty"`
	AdditionalData    map[string]interface{} `yaml:"additionalData,omitempty"`
}

TemplateDir serves a directory of html, md, .tmpl.md, .tmpl.html files. Markdown files are renderer using the given MarkdownBaseTemplateName, which will be looked up in the TemplateDir itself, or using the default renderer if empty.

func (*TemplateDir) ExpandPaths

func (t *TemplateDir) ExpandPaths() error

type TemplateLookupConfig added in v0.3.2

type TemplateLookupConfig struct {
	// Directories is a list of directories that will be searched for templates.
	Directories []string `yaml:"directories,omitempty"`
	// Patterns is a list of glob patterns that will be used to match files in the directories.
	// If the list is empty, the default of **/*.tmpl.md and **/*.tmpl.html will be used
	Patterns []string `yaml:"patterns,omitempty"`
}

TemplateLookupConfig is used to configured a directory based template lookup.

Jump to

Keyboard shortcuts

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