config

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 14 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.

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       *LayerParameters       `yaml:"defaults,omitempty"`
	Overrides      *LayerParameters       `yaml:"overrides,omitempty"`
	Whitelist      *ParameterFilterList   `yaml:"whitelist,omitempty"`
	Blacklist      *ParameterFilterList   `yaml:"blacklist,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  *LayerParameters     `yaml:"defaults,omitempty"`
	Overrides *LayerParameters     `yaml:"overrides,omitempty"`
	Blacklist *ParameterFilterList `yaml:"blackList,omitempty"`
	Whitelist *ParameterFilterList `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 LayerParameters added in v0.5.0

type LayerParameters struct {
	Layers     map[string]map[string]interface{} `yaml:"layers,omitempty"`
	Parameters map[string]interface{}            `yaml:"parameters,omitempty"`
}

func NewLayerParameters added in v0.5.0

func NewLayerParameters() *LayerParameters

func (*LayerParameters) Clone added in v0.5.0

func (p *LayerParameters) Clone() *LayerParameters

func (*LayerParameters) GetParameterMap added in v0.5.0

func (p *LayerParameters) GetParameterMap() map[string]map[string]interface{}

func (*LayerParameters) Merge added in v0.5.0

func (p *LayerParameters) Merge(overrides *LayerParameters)

Merge merges the two LayerParameters, 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 ParameterFilter added in v0.5.0

type ParameterFilter struct {
	Overrides *LayerParameters
	Defaults  *LayerParameters
	Whitelist *ParameterFilterList
	Blacklist *ParameterFilterList
}

func NewParameterFilter added in v0.5.1

func NewParameterFilter(options ...ParameterFilterOption) *ParameterFilter

func (*ParameterFilter) ComputeMiddlewares added in v0.5.0

func (od *ParameterFilter) ComputeMiddlewares(stream bool) []middlewares.Middleware

type ParameterFilterList added in v0.5.0

type ParameterFilterList struct {
	Layers          []string            `yaml:"layers,omitempty"`
	LayerParameters map[string][]string `yaml:"layerParameters,omitempty"`
	Parameters      []string            `yaml:"parameters,omitempty"`
}

ParameterFilterList are used to configure whitelists and blacklists. Entire layers as well as individual flags and arguments can be whitelisted or blacklisted. Params is used for the default layer.

func (*ParameterFilterList) GetAllLayerParameters added in v0.5.0

func (p *ParameterFilterList) GetAllLayerParameters() map[string][]string

type ParameterFilterOption added in v0.5.0

type ParameterFilterOption func(*ParameterFilter)

func WithDefaultParameter added in v0.5.0

func WithDefaultParameter(name string, value string) ParameterFilterOption

func WithLayerDefaults added in v0.4.6

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

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 map[string]interface{}) ParameterFilterOption

func WithMergeDefaults added in v0.4.6

func WithMergeDefaults(defaults *LayerParameters) ParameterFilterOption

func WithMergeOverrideLayer added in v0.4.6

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

func WithMergeOverrides added in v0.4.6

func WithMergeOverrides(overrides *LayerParameters) ParameterFilterOption

func WithOverrideParameter added in v0.5.0

func WithOverrideParameter(name string, value string) ParameterFilterOption

func WithReplaceDefaultLayer added in v0.4.6

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

func WithReplaceDefaults added in v0.4.6

func WithReplaceDefaults(defaults *LayerParameters) ParameterFilterOption

func WithReplaceOverrideLayer added in v0.4.6

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

func WithReplaceOverrides added in v0.4.6

func WithReplaceOverrides(overrides *LayerParameters) ParameterFilterOption

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