middlewares

package
v0.4.36 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 8 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteMiddlewares

func ExecuteMiddlewares(layers_ *layers.ParameterLayers, parsedLayers *layers.ParsedLayers, middlewares ...Middleware) error

ExecuteMiddlewares executes a chain of middlewares with the given parameters. It starts with an initial empty handler, then iteratively wraps it with each middleware. Finally, it calls the resulting handler with the provided layers and parsedLayers.

Middlewares basically get executed in the reverse order they are provided, which means the first given middleware's handler will be called first.

[f1, f2, f3] will be executed as f1(f2(f3(handler)))(layers_, parsedLayers).

How they call the next handler is up to them, but they should always call it.

Usually, the following rules of thumbs work well

  • if all you do is modify the parsedLayers, call `next` first. This means that parsedLayers will be modified in the order of the middlewares. For example, executeMiddlewares(SetFromArgs(), SetFromEnv(), SetFromDefaults()) will first set the defaults, then the environment value, and finally the command line arguments.
  • if you want to modify the layers before parsing, use the call `next` last. This means that the middlewares further down the list will get the newly updated ParameterLayers and thus potentially restrict which parameters they parse.

func Identity

func Identity(layers_ *layers.ParameterLayers, parsedLayers *layers.ParsedLayers) error

Types

type HandlerFunc

type HandlerFunc func(layers *layers.ParameterLayers, parsedLayers *layers.ParsedLayers) error

func BlacklistLayerParametersHandler

func BlacklistLayerParametersHandler(parameters_ map[string][]string) HandlerFunc

func BlacklistLayersHandler

func BlacklistLayersHandler(slugs []string) HandlerFunc

BlacklistLayersHandler removes the specified layers from the given ParameterLayers. It takes a slice of layer slugs, and deletes any layers in the ParameterLayers that match those slugs.

func WhitelistLayerParametersHandler

func WhitelistLayerParametersHandler(parameters_ map[string][]string) HandlerFunc

func WhitelistLayersHandler

func WhitelistLayersHandler(slugs []string) HandlerFunc

WhitelistLayersHandler only leaves the specified layers from the given ParameterLayers. It takes a slice of layer slugs, and deletes any layers in the ParameterLayers that don't match those slugs.

type Middleware

type Middleware func(HandlerFunc) HandlerFunc

func BlacklistLayerParameters

func BlacklistLayerParameters(parameters_ map[string][]string) Middleware

BlacklistLayerParameters is a middleware that removes the given parameters from ParameterLayers after running `next`.

func BlacklistLayerParametersFirst

func BlacklistLayerParametersFirst(parameters_ map[string][]string) Middleware

BlacklistLayerParametersFirst is a middleware that removes the given parameters from ParameterLayers before running `next`.

func BlacklistLayers

func BlacklistLayers(slugs []string) Middleware

BlacklistLayers is a middleware that removes the given layers from ParameterLayers after running `next`.

func BlacklistLayersFirst

func BlacklistLayersFirst(slugs []string) Middleware

BlacklistLayersFirst is a middleware that removes the given layers from ParameterLayers before running `next`.

func Chain

func Chain(ms ...Middleware) Middleware

Chain chains together a list of middlewares into a single middleware. It does this by iteratively wrapping each middleware around the next handler.

func GatherArguments

func GatherArguments(args []string, options ...parameters.ParseStepOption) Middleware

func GatherFlagsFromViper

func GatherFlagsFromViper(options ...parameters.ParseStepOption) Middleware

func LoadParametersFromFile

func LoadParametersFromFile(filename string, options ...parameters.ParseStepOption) Middleware

LoadParametersFromFile loads parameter definitions from a JSON file and applies them to the parameter layers.

func ParseFromCobraCommand

func ParseFromCobraCommand(cmd *cobra.Command, options ...parameters.ParseStepOption) Middleware

func SetFromDefaults

func SetFromDefaults(options ...parameters.ParseStepOption) Middleware

SetFromDefaults is a middleware that sets default values from parameter definitions. It calls the next handler, and then iterates through each layer and parameter definition. If a default is defined, it sets that as the parameter value in the parsed layer.

func UpdateFromEnv

func UpdateFromEnv(prefix string, options ...parameters.ParseStepOption) Middleware

func UpdateFromMap

func UpdateFromMap(m map[string]map[string]interface{}, options ...parameters.ParseStepOption) Middleware

UpdateFromMap takes a map where the keys are layer slugs and the values are maps of parameter name -> value. It calls next, and then merges the provided values into the parsed layers, skipping any layers not present in layers_.

func UpdateFromMapAsDefault

func UpdateFromMapAsDefault(m map[string]map[string]interface{}, options ...parameters.ParseStepOption) Middleware

UpdateFromMapAsDefault takes a map where the keys are layer slugs and the values are maps of parameter name -> value. It calls next, and then merges the provided values into the parsed layers if the parameter hasn't already been set, skipping any layers not present in layers_.

func UpdateFromMapAsDefaultFirst

func UpdateFromMapAsDefaultFirst(m map[string]map[string]interface{}, options ...parameters.ParseStepOption) Middleware

UpdateFromMapAsDefaultFirst takes a map where the keys are layer slugs and the values are maps of parameter name -> value. It calls next, and then merges the provided values into the parsed layers if the parameter hasn't already been set, skipping any layers not present in layers_.

func UpdateFromMapFirst

func UpdateFromMapFirst(m map[string]map[string]interface{}, options ...parameters.ParseStepOption) Middleware

UpdateFromMapFirst takes a map where the keys are layer slugs and the values are maps of parameter name -> value. It calls next, and then merges the provided values into the parsed layers, skipping any layers not present in layers_.

func WhitelistLayerParameters

func WhitelistLayerParameters(parameters_ map[string][]string) Middleware

func WhitelistLayerParametersFirst

func WhitelistLayerParametersFirst(parameters_ map[string][]string) Middleware

func WhitelistLayers

func WhitelistLayers(slugs []string) Middleware

func WhitelistLayersFirst

func WhitelistLayersFirst(slugs []string) Middleware

func WrapWithBlacklistedLayers

func WrapWithBlacklistedLayers(slugs []string, nextMiddlewares ...Middleware) Middleware

WrapWithBlacklistedLayers wraps a middleware that restricts layers to a specified set of slugs, with any additional middlewares. It makes it possible to apply a subset of middlewares to only certain restricted layers.

func WrapWithBlacklistedParameterLayers

func WrapWithBlacklistedParameterLayers(parameters_ map[string][]string, nextMiddlewares ...Middleware) Middleware

func WrapWithLayerModifyingHandler

func WrapWithLayerModifyingHandler(m HandlerFunc, nextMiddlewares ...Middleware) Middleware

WrapWithLayerModifyingHandler wraps a middleware that modifies the layers with additional middlewares. It clones the original layers, calls the layer modifying middleware, chains any additional middlewares, calls next with the original layers, and returns any errors.

This makes it possible to restrict a set of middlewares to only apply to a restricted subset of layers. However, the normal set of middlewares is allowed to continue as normal.

func WrapWithWhitelistedLayers

func WrapWithWhitelistedLayers(slugs []string, nextMiddlewares ...Middleware) Middleware

WrapWithWhitelistedLayers wraps a middleware that restricts layers to a specified set of slugs, with any additional middlewares. It makes it possible to apply a subset of middlewares to only certain restricted layers.

func WrapWithWhitelistedParameterLayers

func WrapWithWhitelistedParameterLayers(parameters_ map[string][]string, nextMiddlewares ...Middleware) Middleware

Jump to

Keyboard shortcuts

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