paramspec

package
Version: v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ColorRegexp = regexp.MustCompile(`^#[0-9a-fA-F]{6}$`)
View Source
var ErrIntegerOutOfRange = errors.New("integer out of range")
View Source
var ErrInvalidNodeName = errors.New("invalid node name")
View Source
var ErrInvalidParameterType = errors.New("invalid parameter type")
View Source
var ErrNilParametersMap = errors.New("parameters map must not be nil")
View Source
var ErrNodeHasBothParamAndSubtree = errors.New("node has both parameter and subtree set")
View Source
var ErrNodeIsEmpty = errors.New("node is empty")
View Source
var ErrRequiredParamMissing = errors.New("required parameter is missing")
View Source
var ErrSubtreeIsNotAMap = errors.New("subtree is not a map")
View Source
var ErrUnknownNode = errors.New("encountered unknown node")
View Source
var NodeNameRegexp = regexp.MustCompile(`^[a-zA-Z0-9]+$`)

Functions

This section is empty.

Types

type Declaration

type Declaration struct {
	Type       ParameterType `json:"type"`
	IsFontName bool          `json:"isFontName,omitempty"`
	Optional   bool          `json:"optional"`
	Example    interface{}   `json:"example,optional,omitempty"`
}

Declaration is the declaration of a single parameter of a ./badges template.

func (*Declaration) ConvertAndValidateParam

func (d *Declaration) ConvertAndValidateParam(param interface{}) (interface{}, error)

ConvertAndValidateParam validates a parameter against the Declaration and converts it to the canonical type as specified in the Declaration's Type field. If the Declaration specifies an Optional field, it is permitted to pass in nil as param without yielding ErrRequiredParamMissing.

func (*Declaration) Validate

func (d *Declaration) Validate() error

type Node

type Node struct {
	Parameter *Declaration `json:"parameter"`
	Subtree   Tree         `json:"subtree"`
}

Node is a node of the parameter specification tree. A valid Node may only contain either a non-nil Parameter or a non-nil Subtree, never both at once.

func (*Node) Validate

func (n *Node) Validate() error

type ParameterType

type ParameterType string
const PTBoolean ParameterType = "boolean"

PTBoolean is a parameter type that allows for the values "true" and false and is passed on to the template as the type bool

const PTColor ParameterType = "color"

PTColor is a parameter type that allows for hexadecimal color codes of format #rrggbb and is passed on to the template as the type string

const PTFloat ParameterType = "float"

PTFloat is a parameter type that allows for IEEE754 floating point numbers with a width of 32 bits and is passed on to the template as the type float32

const PTInteger ParameterType = "integer"

PTInteger is a parameter type that allows for 24-bit signed integer values and is passed on to the template as the type float32

const PTString ParameterType = "string"

PTString is a parameter type that allows for arbitrary strings and is passed on to the template as the type string

func (ParameterType) Convert

func (t ParameterType) Convert(paramValue interface{}) (interface{}, error)

Convert takes a non-nil parameter value and tries to convert it to the ParameterType's canonical type

type Tree

type Tree map[string]Node

Tree is the parameter specification tree, which describes the parameters of a ./badges template. It is the in-memory representation of the parameters.json file found alongside a valid ./badges template. As such, it is designed to be marshalled / unmarshalled using the encoding/json package. Be sure to validate an unmarshalled Tree using the Validate method.

The name of any node may only consist of letters and digits.

func (Tree) ConvertAndValidateParams

func (t Tree) ConvertAndValidateParams(parameters map[string]interface{}) (map[string]interface{}, error)

func (Tree) Lookup

func (t Tree) Lookup(paramPath string) *Declaration

Lookup attempts to retrieve the parameter declaration for the given parameter path, which is a dot-separated path of node names. If no parameter with the given path was found, this function returns nil.

func (Tree) Validate

func (t Tree) Validate() error

Source Files

Jump to

Keyboard shortcuts

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