generator

package
v0.0.0-...-4a5832f Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package generator builds an Agreement from a Template.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(genmodel *Model, val model.Validator, externalIDs bool) (*model.Agreement, error)

Do generates an agreement from a generator model.

This generator receives a model, which contains a Template and a list of variables with their values, and substitutes the placeholders in the template the appropriate variable values. The output is an agreement.

The generator uses text/template syntax for the substitution of the placeholds, i.e., placeholders are of the type {{.var}} to substitute the value of {{.var}} with the value of the key 'var' in the model.Variables map.

A right template should define placeholders in the following paths:

- Details.Client

- Details.Provider if the template is used by more than one provider (if not, the provider can be hardcoded in the template)

- Details.Name

Placeholders may be defined in other paths, e.g. Guarantee[i].Constraint, Details.Expiration

After the substitution, the following fields are modified, regardless of the template content:

- Details.Type: set to agreement type

- Details.Id: UUID value

- Id: equals to agreement.Details.Id

- Details.Creation: current time

- Name: equal to agreement.Details.Name

An error of type validation is returned if the validation on the generated agreement fails. An error of type unreplaced is returned if there is a placeholder that is not substituted. Use IsErrValidation and IsErrUnreplaced to check type of an error.

func IsErrUnreplaced

func IsErrUnreplaced(err error) bool

IsErrUnreplaced checks that the err is an ErrUnreplaced error

func IsErrValidation

func IsErrValidation(err error) bool

IsErrValidation checks that the err is an ErrValidation error

Types

type Model

type Model struct {
	Template  model.Template         `json:"template"`
	Variables map[string]interface{} `json:"variables"`
}

Model contains the parameters needed to do an agreement generation

Jump to

Keyboard shortcuts

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