Documentation ¶
Index ¶
- Constants
- func ParseObjectFromFile(c *gin.Context, name string) (map[string]interface{}, error)
- func ParseStringFromFile(c *gin.Context, name string) (string, error)
- type DefaultParseStep
- type FormParseStep
- type LayerParseState
- type ParseState
- type ParseStep
- type Parser
- type ParserOption
- func WithAppendOverrides(slug string, overrides map[string]interface{}) ParserOption
- func WithAppendParser(slug string, ps ...ParseStep) ParserOption
- func WithGlazeOutputParserOption(output string, tableFormat string) ParserOption
- func WithPrependDefaults(slug string, defaults map[string]interface{}) ParserOption
- func WithPrependParser(slug string, ps ...ParseStep) ParserOption
- func WithReplaceParameters(slug string, overrides map[string]interface{}) ParserOption
- func WithReplaceParser(slug string, ps ...ParseStep) ParserOption
- func WithStopParsing(slug string) ParserOption
- type QueryParseStep
- type StaticParseStep
- type StopParseStep
Constants ¶
const DefaultSlug = "default"
DefaultSlug is used as a drop-in to signal that we actually want to parse the top-level flags and arguments.
TODO(manuel, 2023-06-22) This should be removed once we actually turn default flags and arguments into an actual layer ¶
Variables ¶
This section is empty.
Functions ¶
func ParseObjectFromFile ¶
ParseObjectFromFile takes a multipart.File named `name` from the request and reads it into a map[string]interface{}. If the file is a JSON file (ends with .json), it will be parsed as JSON, if it ends with .yaml or .yml, it will be parsed as YAML.
Types ¶
type DefaultParseStep ¶
type DefaultParseStep struct {
Parameters map[string]interface{}
}
func NewDefaultParseStep ¶
func NewDefaultParseStep(parameters map[string]interface{}) *DefaultParseStep
func (*DefaultParseStep) Parse ¶
func (s *DefaultParseStep) Parse(_ *gin.Context, state *LayerParseState) error
type FormParseStep ¶
type FormParseStep struct {
// contains filtered or unexported fields
}
func NewFormParseStep ¶
func NewFormParseStep(onlyDefined bool) *FormParseStep
func (*FormParseStep) Parse ¶
func (f *FormParseStep) Parse(c *gin.Context, state *LayerParseState) error
func (*FormParseStep) ParseLayerState ¶
func (f *FormParseStep) ParseLayerState(c *gin.Context, state *LayerParseState) error
type LayerParseState ¶
type LayerParseState struct { Slug string // Defaults contains the default values for the parameters, as strings to be parsed // NOTE(manuel, 2023-06-21) Why are these strings? // See also https://github.com/go-go-golems/glazed/issues/239 Defaults map[string]string // Parameters contains the parsed parameters so far Parameters map[string]interface{} // ParameterDefinitions contains the parameter definitions that can still be parsed ParameterDefinitions map[string]*parameters.ParameterDefinition }
type ParseState ¶
type ParseState struct { FlagsAndArguments *LayerParseState Layers map[string]*LayerParseState }
func NewParseStateFromCommandDescription ¶
func NewParseStateFromCommandDescription(cmd cmds.Command) *ParseState
type ParseStep ¶
type ParseStep interface {
Parse(c *gin.Context, result *LayerParseState) error
}
ParseStep is used to parse parameters out of a gin.Context (meaning most certainly out of an incoming *http.Request). These parsed parameters are stored in the ParseState structure. A ParseStep can only parse parameters that are given in the ParameterDefinitions field of the ParseState.
func NewQueryParseStep ¶
type Parser ¶
Parser is contains a list of ParseStep that are used to parse an incoming request into a proper CommandContext, and ultimately be used to Run a glazed Command.
These ParseStep can be operating on the general parameters as well as per layer. The flexibility is there so that more complicated commands can ultimately be built that leverage different validations and rewrite rules.
func NewParser ¶
func NewParser(options ...ParserOption) *Parser
type ParserOption ¶
type ParserOption func(*Parser)
func WithAppendOverrides ¶
func WithAppendOverrides(slug string, overrides map[string]interface{}) ParserOption
WithAppendOverrides is a convenience function to override the parameters of a layer. The overrides are appended past currently present parser functions.
func WithAppendParser ¶
func WithAppendParser(slug string, ps ...ParseStep) ParserOption
WithAppendParser adds the given ParserFunc to the end of the list of layer parsers. Be mindful that this can later on be overwritten by a WithReplaceParser.
func WithGlazeOutputParserOption ¶
func WithGlazeOutputParserOption(output string, tableFormat string) ParserOption
WithGlazeOutputParserOption is a convenience function to override the output and table format glazed settings.
func WithPrependDefaults ¶
func WithPrependDefaults(slug string, defaults map[string]interface{}) ParserOption
WithPrependDefaults is a convenience function to set the initial parameters of a layer. If a value is already set, it won't be overwritten.
func WithPrependParser ¶
func WithPrependParser(slug string, ps ...ParseStep) ParserOption
WithPrependParser adds the given ParserFunc to the beginning of the list of layer parsers. Be mindful that this can later on be overwritten by a WithReplaceParser.
func WithReplaceParameters ¶
func WithReplaceParameters(slug string, overrides map[string]interface{}) ParserOption
WithReplaceParameters is a convenience function to use static layer parsing. This entirely replaces current layer parsers, but can later on be amended with other parsers, for example with WithAppendOverrides.
Note that this also replaces the defaults
func WithReplaceParser ¶
func WithReplaceParser(slug string, ps ...ParseStep) ParserOption
WithReplaceParser replaces the list of layer parsers with the given ParserFunc.
func WithStopParsing ¶
func WithStopParsing(slug string) ParserOption
WithStopParsing will stop parsing parameters, even if further parser steps are added at the end of the parser chain. This can be used to "seal" parsing and prevent further parameters from being overridden.
type QueryParseStep ¶
type QueryParseStep struct {
// contains filtered or unexported fields
}
QueryParseStep parses parameters from the query string of a request.
func (*QueryParseStep) Parse ¶
func (q *QueryParseStep) Parse(c *gin.Context, state *LayerParseState) error
func (*QueryParseStep) ParseLayerState ¶
func (q *QueryParseStep) ParseLayerState(c *gin.Context, state *LayerParseState) error
type StaticParseStep ¶
type StaticParseStep struct {
Parameters map[string]interface{}
}
func NewStaticParseStep ¶
func NewStaticParseStep(parameters map[string]interface{}) *StaticParseStep
func (*StaticParseStep) Parse ¶
func (s *StaticParseStep) Parse(_ *gin.Context, state *LayerParseState) error
type StopParseStep ¶
type StopParseStep struct{}
StopParseStep is a step that stops the parsing process. No more parameter definitions will be parsed after this step.
func NewStopParseStep ¶
func NewStopParseStep() *StopParseStep
func (*StopParseStep) Parse ¶
func (s *StopParseStep) Parse(_ *gin.Context, state *LayerParseState) error