components

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: CC0-1.0 Imports: 11 Imported by: 0

README

Component Development

Overview

Components will evolve over time to incorporate more details and in different ways. However, since this is an actively used tool, it should support all valid component schemas, past and present. The way this is accomplished is by abstracting access to specific versions of components to generic interfaces located in versions/base/component.go.

Development

When creating your component struct, place the appropriate YAML tags on the fields as you would normally for the specific version. Now, whenever you unmarshal your data, it will fill all the fields you want for that version.

Now you must implement the interfaces inside your component structs.

In the case that you want to change how much access you want to give externally, you will need to edit the methods on the interfaces.

Adding A New Version
  1. Create a folder versions/X_Y_Z where the X_Y_Z is the version in semver notation.
  2. Create your Component struct and any other structs that will implement the different interfaces inside here.
  3. Add another variable to represent your version inside of versions/parse.go
  4. Add a check in the switch-case block for your new version that is represented by the variable created in step 3.
    1. Follow the same logic seen in the other versions inside the switch-case block.
  5. Add tests case fixtures with valid and invalid data for your version along with the other fixtures.
  6. Add those cases to the versions/parse_test.go
Editing The Interface
  1. Change the interface(s) inside of interfaces.
  2. Change the implementations for all the component versions (located in versions) to accomodate the interface changes.

For details on the component scheams, consult the schemas repository

tl;dr

All component versions must implement the interface.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ComponentV2_0_0 is a semver representation of version 2.0.0 of component.yaml.
	ComponentV2_0_0 = semver.MustParse("2.0.0")
	// ComponentV3_0_0 is a semver representation of version 3.0.0 of component.yaml.
	ComponentV3_0_0 = semver.MustParse("3.0.0")
	// ComponentV3_1_0 is a semver representation of version 3.1.0 of component.yaml.
	ComponentV3_1_0 = semver.MustParse("3.1.0")
)

Functions

func Load

func Load(path string) (common.Component, error)

Load will read the file at the given path and attempt to return a component object.

Types

type Base

type Base struct {
	SchemaVersion semver.Version `yaml:"-" json:"-"`
}

Base is the bare minimum that every component YAML will have and is used to find the schema version. Complete implementations of component do not need to embed this struct or put it as a field in the component. When this struct is used in the ParseComponent function, it will transfer the version from this struct to the final component struct via SetVersion.

func (*Base) UnmarshalYAML

func (b *Base) UnmarshalYAML(unmarshal func(v interface{}) error) error

UnmarshalYAML is a overridden implementation of YAML parsing the component.yaml This method is similar to the one found here: http://choly.ca/post/go-json-marshalling/ This is necessary because we want to have backwards compatibility with parsing the old types of version 2.0 (type =float). To compensate for that, we have to hand roll our own UnmarshalYAML that can decide what to do for parsing the older version of type float and converting it into semver. In addition, we will use this logic to parse strings into semver.

type BaseComponentParseError

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

BaseComponentParseError is the type of error that will be returned if the parsing failed for ONLY the `Base` struct.

func NewComponentParseError

func NewComponentParseError(message string) BaseComponentParseError

NewComponentParseError is a constructor for creating errors of type BaseComponentParseError

func (BaseComponentParseError) Error

func (b BaseComponentParseError) Error() string

Directories

Path Synopsis
versions

Jump to

Keyboard shortcuts

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