Version: v0.0.0-...-46d7da7 Latest Latest

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

Go to latest
Published: Jul 20, 2018 License: Apache-2.0 Imports: 10 Imported by: 0




This section is empty.


This section is empty.


This section is empty.


type BuilderSupportsTemplateFn

type BuilderSupportsTemplateFn func(hndlrBuilder adapter.HandlerBuilder) bool

BuilderSupportsTemplateFn check if the handlerBuilder supports template.

type CreateInstanceBuilderFn

type CreateInstanceBuilderFn func(instanceName string, instanceParam proto.Message, builder *compiled.ExpressionBuilder) (InstanceBuilderFn, error)

CreateInstanceBuilderFn returns a function that can build instances, based on the instanceParam:

// A CreateInstanceBuilderFn implementation:
func(instanceName string, instanceParam interface{}, builder *compiled.ExpressionBuilder) (InstanceBuilderFn, error) {
  // Call an auto-generated function to create a builder struct.
  builder, err := newMyInstanceBuilder(instanceName, instanceParam, builder)
  if err != nil {
     return nil, err

  // return an InstanceBuilderfn
  func(attrs attribute.Bag) (interface{}, error) {
    // myInstanceBuilder is an instance of a builder struct that this function closes over (see below).
    return myInstanceBuilder.build(bag)

// Auto-generated method for creating a new builder struct
func newMyInstanceBuilder(instanceName string, instanceParam interface{}, exprBuilder *compiled.ExpressionBuilder) (*myInstanceBuilder, error) {
   myInstanceParam := instanceParam.(*myInstanceParam)
   builder := &myInstanceBuilder{}

   builder.field1Builder, err = exprBuilder.Compile(myInstanceParam.field1Expression)
   if err != nil {
     return nil, err

type CreateOutputExpressionsFn

type CreateOutputExpressionsFn func(
	instanceParam proto.Message,
	finder ast.AttributeDescriptorFinder,
	expb *compiled.ExpressionBuilder) (map[string]compiled.Expression, error)

CreateOutputExpressionsFn builds and returns a map of attribute names to the expression for calculating them.

// A CreateOutputExpressionsFn implementation:
func(instanceParam interface{}, finder ast.AttributeDescriptorFinder, builder *compiled.ExpressionBuilder) (map[string]compiled.Expression, error) {

  // Convert the generic instanceParam to its specialized type.
   param := instanceParam.(*myInstanceParam)

  // Create a mapping of expressions back to the attribute names.
  expressions := make(map[string]compiled.Expression, len(param.AttributeBindings))
  for attrName, outExpr := range param.AttributeBindings {
     // compile an expression and put it in expressions.

  return expressions, nil

type DispatchCheckFn

type DispatchCheckFn func(ctx context.Context, handler adapter.Handler, instance interface{}) (adapter.CheckResult, error)

DispatchCheckFn dispatches the instance to the handler.

type DispatchGenerateAttributesFn

type DispatchGenerateAttributesFn func(ctx context.Context, handler adapter.Handler, instance interface{},
	attrs attribute.Bag, mapper OutputMapperFn) (*attribute.MutableBag, error)

DispatchGenerateAttributesFn dispatches the instance object to the attribute generating handler.

type DispatchQuotaFn

type DispatchQuotaFn func(ctx context.Context, handler adapter.Handler, instance interface{}, args adapter.QuotaArgs) (adapter.QuotaResult, error)

DispatchQuotaFn dispatches the instance to the handler.

type DispatchReportFn

type DispatchReportFn func(ctx context.Context, handler adapter.Handler, instances []interface{}) error

DispatchReportFn dispatches the instances to the handler.

type ErrorPath

type ErrorPath struct {
	// contains filtered or unexported fields

ErrorPath represents an error that occurred within a complicated object hierarchy. It allows keeping track of the path to the error location during unwinding, while keeping the amount of garbage generated to a minimum.

func NewErrorPath

func NewErrorPath(path string, cause error) ErrorPath

NewErrorPath gets called, during the unwinding of a generated call in a complicated object hierarchy, to start tracking of the location that the error has occurred.

func (ErrorPath) AsCompilationError

func (e ErrorPath) AsCompilationError(instance string) error

AsCompilationError creates an actual error to be used in the compilation path.

func (ErrorPath) AsEvaluationError

func (e ErrorPath) AsEvaluationError(instance string) error

AsEvaluationError creates an actual error to be used in the evaluation path.

func (ErrorPath) IsNil

func (e ErrorPath) IsNil() bool

IsNil returns if the cause in ErrorPath is nil

func (ErrorPath) WithPrefix

func (e ErrorPath) WithPrefix(prefix string) ErrorPath

WithPrefix adds the given prefix to the error path. Typically, this is called by an intermediate step during unwind to attach its own location information, before returning it up to the caller.

type HandlerSupportsTemplateFn

type HandlerSupportsTemplateFn func(hndlr adapter.Handler) bool

HandlerSupportsTemplateFn check if the handler supports template.

type InferTypeFn

type InferTypeFn func(proto.Message, TypeEvalFn) (proto.Message, error)

InferTypeFn does Type inference from the Instance.params proto message.

type Info

type Info struct {
	Name                    string
	Impl                    string
	Variety                 adptTmpl.TemplateVariety
	BldrInterfaceName       string
	HndlrInterfaceName      string
	CtrCfg                  proto.Message
	InferType               InferTypeFn
	SetType                 SetTypeFn
	BuilderSupportsTemplate BuilderSupportsTemplateFn
	HandlerSupportsTemplate HandlerSupportsTemplateFn

	AttributeManifests []*pb.AttributeManifest

	DispatchReport   DispatchReportFn
	DispatchCheck    DispatchCheckFn
	DispatchQuota    DispatchQuotaFn
	DispatchGenAttrs DispatchGenerateAttributesFn

	CreateInstanceBuilder   CreateInstanceBuilderFn
	CreateOutputExpressions CreateOutputExpressionsFn

Info contains all the information related a template like Default instance params, type inference method etc.

type InstanceBuilderFn

type InstanceBuilderFn func(attrs attribute.Bag) (interface{}, error)

InstanceBuilderFn builds and returns an instance, based on the attributes supplied. Typically, InstanceBuilderFn closes over an auto-generated "builder" struct which contains compiled expressions and sub-builders for the instance:

// An InstanceBuilderFn implementation:
func(attrs attribute.Bag) (interface{}, error) {
  // myInstanceBuilder is an instance of a builder struct that this function closes over (see below).
  return myInstanceBuilder.build(bag)

// myInstanceBuilder is an auto-generated struct for building instances. They get instantiated
// based on instance parameters (see CreateInstanceBuilderFn documentation):
type myInstanceBuilder struct {

   // field1Builder builds the value of the field field1 of the instance.
   field1Builder compiled.Expression

func (b *myInstanceBuilder) build(attrs attribute.Bag) (*myInstance, error) {
  instance := &myInstance{}

  // Build the value of field1
  if instance1.field1, err = b.field1Builder.EvaluateString(bag); err != nil {
     return nil, err
  return instance, nil

type OutputMapperFn

type OutputMapperFn func(attrs attribute.Bag) (*attribute.MutableBag, error)

OutputMapperFn maps the results of an APA output bag, with "$out"s, by processing it through AttributeBindings.

MapperFn: func(attrs attribute.Bag) (*attribute.MutableBag, error) {...}

ProcessGenerateAttributes2Fn(..., attrs attribute.Bag) (*attribute.MutableBag, error) [
  // use instance to call into the handler and get back a bag with "$out" values in it.
  outBag := ...

  // Call an OutputMapperFn to map "$out.<name>" parameters to actual attribute values
  resultBag := MapperFn(outBag)
  return resultBag, nil

func NewOutputMapperFn

func NewOutputMapperFn(expressions map[string]compiled.Expression) OutputMapperFn

NewOutputMapperFn creates and returns a function that creates new attributes, based on the supplied expression set.

type Repository

type Repository interface {
	GetTemplateInfo(template string) (Info, bool)
	SupportsTemplate(hndlrBuilder adapter.HandlerBuilder, tmpl string) (bool, string)

Repository defines all the helper functions to access the generated template specific types and fields.

func NewRepository

func NewRepository(templateInfos map[string]Info) Repository

NewRepository returns an implementation of Repository

type SetTypeFn

type SetTypeFn func(types map[string]proto.Message, builder adapter.HandlerBuilder)

SetTypeFn dispatches the inferred types to handlers

type TypeEvalFn

type TypeEvalFn func(string) (pb.ValueType, error)

TypeEvalFn evaluates an expression and returns the ValueType for the expression.

Jump to

Keyboard shortcuts

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