Documentation ¶
Overview ¶
Package cbc provides a set of Common Basic Components.
Name is take from the similar namespace used in UBL.
Index ¶
- Variables
- func CodeMapHas(keys ...Key) validation.Rule
- func HasValidKeyIn(keys ...Key) validation.Rule
- func InCodeDefs(list []*Definition) validation.Rule
- func InKeyDefs(list []*Definition) validation.Rule
- func KeyStrings(keys []Key) []string
- type Code
- type CodeMap
- type Definition
- type Key
- type Meta
Constants ¶
This section is empty.
Variables ¶
var ( CodePattern = `^[A-Za-z0-9]+([\.\-\/ _\:]?[A-Za-z0-9]+)*$` CodePatternRegexp = regexp.MustCompile(CodePattern) CodeMinLength uint64 = 1 CodeMaxLength uint64 = 32 )
Basic code constants.
var ( // KeyPattern describes what should keys look like KeyPattern = `^(?:[a-z]|[a-z0-9][a-z0-9-+]*[a-z0-9])$` // KeyValidationRegexp is used for key validation KeyValidationRegexp = regexp.MustCompile(KeyPattern) // KeySeparator is used to separate keys join using the "With" // method. KeySeparator = "+" )
var ( // KeyMinLength defines the minimum key length KeyMinLength uint64 = 1 // KeyMaxLength defines the maximum key length KeyMaxLength uint64 = 64 )
Functions ¶
func CodeMapHas ¶ added in v0.55.0
func CodeMapHas(keys ...Key) validation.Rule
CodeMapHas returns a validation rule that ensures the code set contains the provided keys.
func HasValidKeyIn ¶ added in v0.50.0
func HasValidKeyIn(keys ...Key) validation.Rule
HasValidKeyIn provides a validator to check the Key's value is within the provided known set.
func InCodeDefs ¶ added in v0.207.0
func InCodeDefs(list []*Definition) validation.Rule
InCodeDefs prepares a validation to provide a rule that will determine if the codes are in the provided set.
func InKeyDefs ¶ added in v0.69.0
func InKeyDefs(list []*Definition) validation.Rule
InKeyDefs prepares a validation to provide a rule that will determine if the keys are in the provided set.
func KeyStrings ¶ added in v0.81.0
KeyStrings is a convenience method to convert a list of keys into a list of strings.
Types ¶
type Code ¶
type Code string
Code represents a string used to uniquely identify the data we're looking at. We use "code" instead of "id", to reenforce the fact that codes should be more easily set and used by humans within definitions than IDs or UUIDs. Codes are standardised so that when validated they must contain between 1 and 32 inclusive english alphabet letters or numbers with optional periods (`.`), dashes (`-`), underscores (`_`), forward slashes (`/`), colons (`:`) or spaces (` `) to separate blocks. Each block must only be separated by a single symbol.
The objective is to have a code that is easy to read and understand, while still being unique and easy to validate.
const CodeEmpty Code = ""
CodeEmpty is used when no code is defined.
const ( // DefaultCodeSeparator is the default separator used to join codes. DefaultCodeSeparator Code = "-" )
func DefinitionCodes ¶ added in v0.207.0
func DefinitionCodes(list []*Definition) []Code
DefinitionCodes helps extract the codes from a list of key definitions.
func NormalizeAlphanumericalCode ¶ added in v0.204.0
NormalizeAlphanumericalCode cleans and normalizes the code, ensuring all letters are uppercase while also removing non-alphanumerical characters.
func NormalizeCode ¶ added in v0.200.0
NormalizeCode attempts to clean and normalize the provided code so that it matches what we'd expect instead of raising validation errors.
func NormalizeNumericalCode ¶ added in v0.204.0
NormalizeNumericalCode cleans and normalizes the code, while also removing non-numerical characters.
func (Code) JSONSchema ¶
func (Code) JSONSchema() *jsonschema.Schema
JSONSchema provides a representation of the struct for usage in Schema.
func (Code) Join ¶ added in v0.202.0
Join returns a new code that is the result of joining the provided code with the current one using a default separator.
type CodeMap ¶ added in v0.55.0
CodeMap is a map of keys to specific codes, useful to determine regime specific codes from their key counterparts.
func (CodeMap) Equals ¶ added in v0.55.0
Equals returns true if the code map has the same keys and values as the provided map.
func (CodeMap) Has ¶ added in v0.55.0
Has returns true if the code map has values for all the provided keys.
func (CodeMap) JSONSchemaExtend ¶ added in v0.55.0
func (CodeMap) JSONSchemaExtend(schema *jsonschema.Schema)
JSONSchemaExtend ensures the pattern property is set correctly.
type Definition ¶ added in v0.207.0
type Definition struct { // Key being defined. Key Key `json:"key,omitempty" jsonschema:"title=Key"` // Code this definition represents. Code Code `json:"code,omitempty" jsonschema:"title=Code"` // Short name for the key. Name i18n.String `json:"name" jsonschema:"title=Name"` // Description offering more details about when the key should be used. Desc i18n.String `json:"desc,omitempty" jsonschema:"title=Description"` // Meta defines any additional details that may be useful or associated // with the key. Meta Meta `json:"meta,omitempty" jsonschema:"title=Meta"` // Values defines the possible values associated with the key, which themselves will // either be keys or codes depending on the context. Values []*Definition `json:"values,omitempty" jsonschema:"title=Values"` // Pattern is used to validate the key value instead of using a fixed value // from the code or key definitions. Pattern string `json:"pattern,omitempty" jsonschema:"title=Pattern"` // Map helps map local keys to specific codes, useful for converting the // described key into a local code. Map CodeMap `json:"map,omitempty" jsonschema:"title=Code Map"` }
Definition defines properties of a key, code, or other value that has a specific meaning or utility.
func GetCodeDefinition ¶ added in v0.207.0
func GetCodeDefinition(code Code, list []*Definition) *Definition
GetCodeDefinition helps fetch the code definition instance from a list.
func GetKeyDefinition ¶ added in v0.69.0
func GetKeyDefinition(key Key, list []*Definition) *Definition
GetKeyDefinition helps fetch the key definition instance from a list.
func (*Definition) CodeDef ¶ added in v0.207.0
func (d *Definition) CodeDef(code Code) *Definition
CodeDef searches the list of values and provides the matching definition.
func (*Definition) HasCode ¶ added in v0.207.0
func (d *Definition) HasCode(code Code) bool
HasCode loops through values and determines if there is a match for the code.
func (*Definition) HasKey ¶ added in v0.207.0
func (d *Definition) HasKey(key Key) bool
HasKey loops through values and determines if there is a match for the key.
func (*Definition) KeyDef ¶ added in v0.207.0
func (d *Definition) KeyDef(key Key) *Definition
KeyDef searches the list of values and provides the matching definition.
func (*Definition) Validate ¶ added in v0.207.0
func (d *Definition) Validate() error
Validate ensures the definition looks correct.
type Key ¶
type Key string
Key is used to define an ID or code that more closely represents a human name. The objective is to make it easier to define constants that can be re-used more easily.
const KeyEmpty Key = ""
KeyEmpty is used when no key is available.
func AppendUniqueKeys ¶ added in v0.204.0
AppendUniqueKeys is a convenience method to append keys to a list ensuring that any existing keys are not re-added.
func DefinitionKeys ¶ added in v0.81.0
func DefinitionKeys(list []*Definition) []Key
DefinitionKeys helps extract the keys from a list of key definitions.
func (Key) HasPrefix ¶ added in v0.50.0
HasPrefix checks to see if the key starts with the provided key. As per `Has`, only the complete key between `+` symbols are matched.
func (Key) JSONSchema ¶
func (Key) JSONSchema() *jsonschema.Schema
JSONSchema provides a representation of the struct for usage in Schema.
func (Key) Pop ¶ added in v0.207.0
Pop removes the last key from a list and returns the remaining base, or an empty key if there is nothing left.
Example:
Key("a+b+c").Pop() => Key("a+b")
type Meta ¶
Meta defines a structure for data about the data being defined. Typically would be used for adding additional IDs or specifications not already defined or required by the base structure.
GOBL is focussed on ensuring the recipient has everything they need, as such, meta should only be used for data that may be used by intermediary conversion processes that should not be needed by the end-user.
We need to always use strings for values so that meta-data is easy to convert into other formats, such as protobuf which has strict type requirements.
func (Meta) JSONSchemaExtend ¶ added in v0.50.0
func (Meta) JSONSchemaExtend(schema *jsonschema.Schema)
JSONSchemaExtend ensures the meta keys are valid.