dslengine

package
v0.0.0-...-d1a11ac Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Caller

func Caller() string

Caller returns the name of calling function.

func CanUse

func CanUse(client, provider Versioned) error

CanUse returns nil if the provider supports all the versions supported by the client or if the provider is unversioned.

func Execute

func Execute(dsl func(), def Definition) bool

Execute runs the given DSL to initialize the given definition. It returns true on success. It returns false and appends to Errors on failure. Note that `Run` takes care of calling `Execute` on all definitions that implement Source. This function is intended for use by definitions that run the DSL at declaration time rather than store the DSL for execution by the dsl (usually simple independent definitions). The DSL should use ReportError to record DSL execution errors.

func IncompatibleDSL

func IncompatibleDSL(dslFunc string)

IncompatibleDSL should be called by DSL functions when they are invoked in an incorrect context (e.g. "Params" in "Resource").

func InvalidArgError

func InvalidArgError(expected string, actual interface{})

InvalidArgError records an invalid argument error. It is used by DSL functions that take dynamic arguments.

func ReportError

func ReportError(fm string, vals ...interface{})

ReportError records a DSL error for reporting post DSL execution.

func Run

func Run() error

Run runs the given root definitions. It iterates over the definition sets multiple times to first execute the DSL, the validate the resulting definitions and finally finalize them. The executed DSL may append new roots to the Roots Design package variable to have them be executed (last) in the same run.

func TopLevelDefinition

func TopLevelDefinition(failItNotTopLevel bool) bool

TopLevelDefinition returns true if the currently evaluated DSL is a root DSL (i.e. is not being run in the context of another definition).

Types

type Definition

type Definition interface {
	// Context is used to build error messages that refer to the definition.
	Context() string
}

Definition is the common interface implemented by all definitions.

func CurrentDefinition

func CurrentDefinition() Definition

CurrentDefinition returns the definition whose initialization DSL is currently being executed.

type DefinitionSet

type DefinitionSet []Definition

DefinitionSet contains DSL definitions that are executed as one unit. The slice elements may implement the Validate an, Source interfaces to enable the corresponding behaviors during DSL execution.

type EnumValidationDefinition

type EnumValidationDefinition struct {
	Values []interface{}
}

EnumValidationDefinition represents an enum validation as described at http://json-schema.org/latest/json-schema-validation.html#anchor76.

func (*EnumValidationDefinition) Context

func (v *EnumValidationDefinition) Context() string

Context returns the generic definition name used in error messages.

type Error

type Error struct {
	GoError error
	File    string
	Line    int
}

Error represents an error that occurred while running the API DSL. It contains the name of the file and line number of where the error occurred as well as the original Go error.

func (*Error) Error

func (de *Error) Error() string

Error returns the underlying error message.

type Finalize

type Finalize interface {
	Definition
	// Finalize is run by the DSL runner once the definition DSL has executed and the
	// definition has been validated.
	Finalize()
}

Finalize is the interface implemented by definitions that require an additional pass after the DSL has executed (e.g. to merge generated definitions or initialize default values)

type FormatValidationDefinition

type FormatValidationDefinition struct {
	Format string
}

FormatValidationDefinition represents a format validation as described at http://json-schema.org/latest/json-schema-validation.html#anchor104.

func (*FormatValidationDefinition) Context

func (f *FormatValidationDefinition) Context() string

Context returns the generic definition name used in error messages.

type MaxLengthValidationDefinition

type MaxLengthValidationDefinition struct {
	MaxLength int
}

MaxLengthValidationDefinition represents an maximum length validation as described at http://json-schema.org/latest/json-schema-validation.html#anchor26.

func (*MaxLengthValidationDefinition) Context

Context returns the generic definition name used in error messages.

type MaximumValidationDefinition

type MaximumValidationDefinition struct {
	Max float64
}

MaximumValidationDefinition represents a maximum value validation as described at http://json-schema.org/latest/json-schema-validation.html#anchor17.

func (*MaximumValidationDefinition) Context

func (m *MaximumValidationDefinition) Context() string

Context returns the generic definition name used in error messages.

type MetadataDefinition

type MetadataDefinition map[string][]string

MetadataDefinition is a set of key/value pairs

type MinLengthValidationDefinition

type MinLengthValidationDefinition struct {
	MinLength int
}

MinLengthValidationDefinition represents an minimum length validation as described at http://json-schema.org/latest/json-schema-validation.html#anchor29.

func (*MinLengthValidationDefinition) Context

Context returns the generic definition name used in error messages.

type MinimumValidationDefinition

type MinimumValidationDefinition struct {
	Min float64
}

MinimumValidationDefinition represents an minimum value validation as described at http://json-schema.org/latest/json-schema-validation.html#anchor21.

func (*MinimumValidationDefinition) Context

func (m *MinimumValidationDefinition) Context() string

Context returns the generic definition name used in error messages.

type MultiError

type MultiError []*Error

MultiError collects all DSL errors. It implements error.

var (
	// Errors contains the DSL execution errors if any.
	Errors MultiError

	// Roots contains the root definition sets built by the DSLs.
	// DSL implementations should append to it to ensure the DSL gets executed by the runner.
	// Note that a root definition is a different concept from a "top level" definition (i.e. a
	// definition that is an entry point in the DSL). In particular a root definition may include
	// an arbitrary number of definition sets forming a tree of definitions.
	// For example the API DSL only has one root definition (the API definition) but many top level
	// definitions (API, Version, Type, MediaType etc.) all defining a definition set.
	Roots []Root
)

func (MultiError) Error

func (m MultiError) Error() string

Error returns the error message.

type PatternValidationDefinition

type PatternValidationDefinition struct {
	Pattern string
}

PatternValidationDefinition represents a pattern validation as described at http://json-schema.org/latest/json-schema-validation.html#anchor33

func (*PatternValidationDefinition) Context

func (f *PatternValidationDefinition) Context() string

Context returns the generic definition name used in error messages.

type RequiredValidationDefinition

type RequiredValidationDefinition struct {
	Names []string
}

RequiredValidationDefinition represents a required validation as described at http://json-schema.org/latest/json-schema-validation.html#anchor61.

func (*RequiredValidationDefinition) Context

func (r *RequiredValidationDefinition) Context() string

Context returns the generic definition name used in error messages.

type Root

type Root interface {
	// IterateSets calls the given iterator passing in each definition set sorted in
	// execution order.
	IterateSets(SetIterator)
}

Root is the interface implemented by the DSL root objects held by the Roots variable. These objects contains all the definition sets created by the DSL and can be passed to the dsl for execution.

type SetIterator

type SetIterator func(s DefinitionSet) error

SetIterator is the function signature used to iterate over definition sets with IterateSets.

type Source

type Source interface {
	Definition
	// DSL returns the DSL used to initialize the definition if any.
	DSL() func()
}

Source is the interface implemented by definitions that can be initialized via DSL.

type TraitDefinition

type TraitDefinition struct {
	// Trait name
	Name string
	// Trait DSL
	DSLFunc func()
}

TraitDefinition defines a set of reusable properties.

func (*TraitDefinition) Context

func (t *TraitDefinition) Context() string

Context returns the generic definition name used in error messages.

func (*TraitDefinition) DSL

func (t *TraitDefinition) DSL() func()

DSL returns the initialization DSL.

type Validate

type Validate interface {
	Definition
	// Validate returns nil if the definition contains no validation error.
	// The Validate implementation may take advantage of ValidationErrors to report
	// more than one errors at a time.
	Validate() error
}

Validate is the interface implemented by definitions that can be validated. Validation is done by the DSL dsl post execution.

type ValidationDefinition

type ValidationDefinition interface {
	Definition
}

ValidationDefinition is the common interface for all validation data structures. It doesn't expose any method and simply exists to help with documentation.

type ValidationErrors

type ValidationErrors struct {
	Errors      []error
	Definitions []Definition
}

ValidationErrors records the errors encountered when running Validate.

func (*ValidationErrors) Add

func (verr *ValidationErrors) Add(def Definition, format string, vals ...interface{})

Add adds a validation error to the target.

func (*ValidationErrors) AddError

func (verr *ValidationErrors) AddError(def Definition, err error)

AddError adds a validation error to the target. AddError "flattens" validation errors so that the recorded errors are never ValidationErrors themselves.

func (*ValidationErrors) AsError

func (verr *ValidationErrors) AsError() *ValidationErrors

AsError returns an error if there are validation errors, nil otherwise.

func (*ValidationErrors) Error

func (verr *ValidationErrors) Error() string

Error implements the error interface.

func (*ValidationErrors) Merge

func (verr *ValidationErrors) Merge(err *ValidationErrors)

Merge merges validation errors into the target.

type Versioned

type Versioned interface {
	Definition
	// Versions returns an array of supported versions if the object is versioned, nil
	// othewise.
	Versions() []string
	// SupportsVersion returns true if the object supports the given version.
	SupportsVersion(ver string) bool
	// SupportsNoVersion returns true if the object is unversioned.
	SupportsNoVersion() bool
}

Versioned is implemented by potentially versioned definitions such as API resources.

Jump to

Keyboard shortcuts

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