specs

package
v2.1.1-0...-182a82a Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 14 Imported by: 0

README

Semaphore

Semaphore is a tool to orchestrate your microservices by providing a powerful toolset for manipulating, forwarding and returning properties from and to multiple services.

Semaphore is built on top of schema definitions and flows. Messages are strictly typed and are type-checked. Payloads such as protobuf and JSON could be generated from the same definitions.

Table of contents

Specification

Resources

Objects (ex: input, call or responses) holding or representing data are called resources. Resources are only populated after they have been called.

Some resources hold multiple resource properties. The default resource property is used when no resource property is given. The following resource properties are available:

Input
  • request - default
  • header
Call
  • request
  • response - default
  • header
Template reference

Templates could reference properties inside other resources. Templates are defined following the mustache template system. Templates start with the resource definition. The default resource property is used when no resource property is given.

Paths reference a property within the resource. Paths could target nested messages or repeated values.

{{ call.request:address.street }}
Message

A message holds properties, nested messages and/or repeated messages. All of these properties could be referenced. Messages reference a schema message. Properties Properties hold constant values and/or references. Properties are strictly typed and use the referenced schema message for type checks. Properties could also hold references which should match the given property type. Nested messages You can define and use message types inside other message types, as in the following example.

message "address" {
    message "country" {

    }
}
Repeated message

Repeated messages accept two labels the first one is its alias and the second one is the resource reference. If a repeated message is kept empty the whole message is attempted to be copied.

repeated "address" "input:address" {
    message "country" {

    }
}
Flow

A flow defines a set of calls that should be called chronologically and produces an output message. Calls could reference other resources when constructing messages. All references are strictly typed. Properties are fetched from the given schema or inputs.

All flows should contain a unique name. Calls are nested inside of flows and contain two labels, a unique name within the flow and the service and method to be called. A dependency reference structure is generated within the flow which allows Semaphore to figure out which calls could be called parallel to improve performance.

An optional schema could be defined which defines the request/response messages.

flow "Logger" {
    input "schema.Object" {
    }

    resource "log" {
        request "com.project.Logger" "Log" {
            message = "{{ input:message }}"
        }
    }

    output "schema.Object" {
        status = "{{ log:status }}"
        code = "{{ log:code }}"
    }   
}
Schema

A schema definition defines the input and output message types. When a flow schema is defined are the input properties (except header) ignored.

flow "Logger" {
    schema = "exposed.Logger.Log"
}
Input

The input represents a schema definition. The schema definition defines the message format. Additional options or headers could be defined here as well.

input "schema.Object" {
    header = ["Authorization"]
}
Output

The output acts as a message. The output could contain nested messages and repeated messages. The output could also define the response header.

output "schema.Object" {
  header {
    Cookie = "mnomnom"
  }

  status = "{{ log:status }}"
}
Conditions

Conditions could be wrapped around resources. The wrapped resources are executed if the condition results in a boolean which is true. Conditions could be nested and resources inside a condition block could be referenced inside other resources and the output.

flow "condition" {
  input "schema.Object" {}

  if "{{ input:kind }} == 'INSERT'" {
    resource "insert" {}

    if "{{ insert:upgrade }} == true" {
      resource "upgrade" {}
    }
  }
}
Resource

A call calls the given service and method. Calls could be executed synchronously or asynchronously. All calls are referencing a service method, the service should match the alias defined inside the service. The request and response schema messages are used for type definitions. A call could contain the request headers, request body and rollback.

# Calling service alias logger.Log
resource "log" {
  request "com.project.Logger" "Log" {
    message = "{{ input:message }}"
  }
}
Depends on

Marks resources as dependencies. This could be usefull if a resource does not have a direct reference dependency.

resource "warehouse" {
  request "com.project.Wharehouse" "Ship" {
    product = "{{ input:product }}"
  }
}

resource "log" {
  depends_on = ["warehouse"]

  request "com.project.Logger" "Log" {
    message = "{{ input:message }}"
  }
}
Options

Options could be consumed by implementations. The defined key/values are implementation-specific.

resource "log" {
    request "logger" "Log" {
        options {
            // HTTP method
            method = "GET"
        }
    }
}
Header

Headers are represented as keys and values. Both keys and values are strings. Values could reference properties from other resources.

input "schema.Input" {
    header = ["Authorization"]
}

resource "log" {
    request "com.project" "Log" {
        header {
            Authorization = "{{ input.header:Authorization }}"
        }
    }
}
Request

The request acts as a message. The request could contain nested messages and repeated messages.

resource "log" {
    request "logger" "Log" {
        key = "value"
    }
}
Rollback

Rollbacks are called in a reversed chronological order when a call inside the flow fails. All rollbacks are called async and errors are not handled. Rollbacks consist of a call endpoint and a request message. Rollback templates could only reference properties from any previous calls and the input.

resource "log" {
    rollback "logger" "Log" {
        header {
            Claim = "{{ input:Claim }}"
        }
        
        message = "Something went wrong"
    }
}
Proxy

A proxy streams the incoming request to the given service. Proxies could define calls that are executed before the request body is forwarded. The input.request resource is unavailable in proxy calls. A proxy forward could ideally be used for file uploads or large messages which could not be stored in memory.

proxy "upload" {
    resource "auth" {
        request "com.project" "Authenticate" {
            header {
                Authorization = "{{ input.header:Authorization }}"
            }
        }
    }

    resource "logger" {
        request "com.project" "Log" {
            message = "{{ auth:claim }}"
        }
    }

    forward "com.project.Uploader" {
        header {
            StorageKey = "{{ auth:key }}"
        }
    }
}
Service

Services represent external service which could be called inside the flows. The service name is an alias that could be referenced inside calls. The host of the service and schema service method should be defined for each service. The request and response message defined inside the schema are used for type definitions. The FQN (fully qualified name) of the schema method should be used. Each service references a caller implementation to be used.

Codec is the message format used for request and response messages.

service "logger" "http" {
    codec = "proto"
    host = "https://service.prod.svc.cluster.local"
}
Options

Options could be consumed by implementations. The defined key/values are implementation-specific.

options {
    port = 8080
}
Error Handling

Custom error messages, status codes and response objects could be defined inside your flows. These objects could reference properties and be overriden with constant values. Error handling consists out of two blocks. error which defines the custom response object. These objects are returned to the user if the protocol allows for dynamic error objects (such as HTTP). on_error allows for the definitions of parameters (params) and to override the message and status properties. Optionally could a schema be defined. This schema is used to decode the received message. The default error properties (message and status), error params and other resources could be referenced inside the on_error and error blocks.

flow "greeter" {
    on_error {
        message = "unexpected error"
        status = 500
    }

    resource "echo" {
        error "com.Schema" {
            message "meta" {
                status = "{{ error:status }}"
                trace = "{{ error.params:trace }}"
            }

            message = "{{ error:message }}"
        }

        on_error {
            schema = "com.Schema"
            message = "{{ echo.error:message }}"
            status = 401

            params {
                trace = "{{ echo.error:trace }}"
            }
        }
    }
}

If no error object is defined is the parent error object copied.

error "com.Schema" {
    message "meta" {
        status = "{{ error:status }}"
    }

    message = "{{ error:message }}"
}

flow "greeter" {
    # copies the global error object if not set

    resource "echo" {
        # copies the flow error object if not set
    }
}
Endpoint

An endpoint exposes a flow. Endpoints are not parsed by Semaphore and have custom implementations in each caller. The name of the endpoint represents the flow which should be executed.

All servers should define their own request/response message formats.

endpoint "users" "http" {
    method = "GET"
    endpoint = "/users/:project"
    status = "202"
    codec = "json"
}
Options

Options could be consumed by implementations. The defined key/values are implementation-specific.

endpoint "users" "http" {
    options {
        port = 8080
    }
}

Functions

Custom defined functions could be configured and passed to Semaphore. Functions could be called inside templates and could accept arguments and return a property as a response. Functions could be used to preform computation on properties during runtime. Functions have read access to the entire reference store but could only write to their own stack. A unique resource is created for each function call where all references stored during runtime are located. This resource is created during compile time and references made to the given function are automatically adjusted.

A function should always return a property where all paths are absolute. This way it is easier for other properties to reference a resource.

function(...<arguments>)
resource "auth" {
    request "com.project" "Authenticate" {
        header {
            Authorization = "{{ jwt(input.header:Authorization) }}"
        }
    }
}

Documentation

Index

Constants

View Source
const (
	// TemplateOpen tag
	TemplateOpen = "{{"
	// TemplateClose tag
	TemplateClose = "}}"

	// PathDelimiter represents the path reference delimiter
	PathDelimiter = "."

	// InputResource key
	InputResource = "input"
	// OutputResource key
	OutputResource = "output"
	// StackResource property
	StackResource = "stack"
	// ParamsResource property
	ParamsResource = "params"
	// RequestResource property
	RequestResource = "request"
	// HeaderResource property
	HeaderResource = "header"
	// ResponseResource property
	ResponseResource = "response"
	// ErrorResource property
	ErrorResource = "error"

	// DefaultInputResource represents the default input property on resource select
	DefaultInputResource = RequestResource
	// DefaultCallResource represents the default call property on resource select
	DefaultCallResource = ResponseResource
)
View Source
const ReferenceDelimiter = ":"

ReferenceDelimiter represents the value resource reference delimiter.

Variables

This section is empty.

Functions

func GetTemplateContent

func GetTemplateContent(value string) string

GetTemplateContent trims the opening and closing tags from the given template value

func IsReference

func IsReference(value string) bool

IsReference returns true if the given value is a reference value

func IsString

func IsString(value string) bool

IsString returns true if the given value is a string value

func IsTemplate

func IsTemplate(value string) bool

IsTemplate checks whether the given value is a template

func JoinPath

func JoinPath(values ...string) (result string)

JoinPath joins the given flow paths

func ResourcePath

func ResourcePath(resource string, paths ...string) string

ResourcePath constructs a new path using the given resource and path.

func SplitPath

func SplitPath(path string) []string

SplitPath splits the given path into parts

Types

type Call

type Call struct {
	*metadata.Meta
	Service    string        `json:"service,omitempty"`
	Method     string        `json:"method,omitempty"`
	Request    *ParameterMap `json:"request,omitempty"`
	Response   *ParameterMap `json:"response,omitempty"`
	Descriptor *Method       `json:"-"`
}

Call represents a call which is executed during runtime

type Condition

type Condition struct {
	*metadata.Meta
	RawExpression string `json:"raw_expression,omitempty"`
	Evaluable     `json:"-"`
	Params        *ParameterMap `json:"-"`
}

Condition represents a condition which could be true or false

func (Condition) GetParameters

func (c Condition) GetParameters() *ParameterMap

GetParameters returns the list of parameters

type Dependencies

type Dependencies map[string]*Node

Dependencies represents a collection of node dependencies

func (Dependencies) Append

func (dependencies Dependencies) Append(input Dependencies) Dependencies

Append appends the given input to the already existing dependencies and returns the result

type Endpoint

type Endpoint struct {
	*metadata.Meta
	Flow     string  `json:"flow,omitempty"`
	Listener string  `json:"listener,omitempty"`
	Options  Options `json:"options,omitempty"`
}

Endpoint exposes a flow. Endpoints are not parsed by Semaphore and have custom implementations in each caller. The name of the endpoint represents the flow which should be executed.

type EndpointList

type EndpointList []*Endpoint

EndpointList represents a collection of endpoints

func (*EndpointList) Append

func (endpoints *EndpointList) Append(list EndpointList)

Append merges the incoming manifest to the existing (left) manifest

func (EndpointList) Get

func (endpoints EndpointList) Get(flow string) []*Endpoint

Get returns all endpoints for the given flow

type Enum

type Enum struct {
	*metadata.Meta
	Name        string                `json:"name,omitempty" yaml:"name,omitempty"`
	Description string                `json:"description,omitempty" yaml:"description,omitempty"`
	Keys        map[string]*EnumValue `json:"keys,omitempty" yaml:"keys,omitempty"`
	Positions   map[int32]*EnumValue  `json:"positions,omitempty" yaml:"positions,omitempty"`
}

Enum represents a enum configuration

func (Enum) Clone

func (enum Enum) Clone() *Enum

Clone enum schema.

func (*Enum) Compare

func (enum *Enum) Compare(expected *Enum) error

Compare the given enum value against of the expected one and return the first met difference as error.

type EnumValue

type EnumValue struct {
	*metadata.Meta
	Key         string `json:"key,omitempty"`
	Position    int32  `json:"position,omitempty"`
	Description string `json:"description,omitempty"`
}

EnumValue represents a enum configuration

func (*EnumValue) Compare

func (value *EnumValue) Compare(expected *EnumValue) error

Compare the given enum value against the expected one and returns the first met difference as error.

type ErrLabelMismatch

type ErrLabelMismatch struct {
	Label    labels.Label
	Expected labels.Label
	Path     string
	Expr     Expression
}

ErrLabelMismatch occurs when given label does not match with expected label

func (ErrLabelMismatch) Error

func (e ErrLabelMismatch) Error() string

Error returns a description of the given error as a string

func (ErrLabelMismatch) Prettify

func (e ErrLabelMismatch) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

type ErrPathNotFound

type ErrPathNotFound struct {
	Path string
}

ErrPathNotFound occurs when path cannot be resolved

func (ErrPathNotFound) Error

func (e ErrPathNotFound) Error() string

Error returns a description of the given error as a string

func (ErrPathNotFound) Prettify

func (e ErrPathNotFound) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

type ErrTypeMismatch

type ErrTypeMismatch struct {
	Type     interface{}
	Expected interface{}
	Path     string
	Expr     Expression
}

ErrTypeMismatch occurs when given typs does not match with expected type

func (ErrTypeMismatch) Error

func (e ErrTypeMismatch) Error() string

Error returns a description of the given error as a string

func (ErrTypeMismatch) Prettify

func (e ErrTypeMismatch) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

type ErrUndeclaredSchema

type ErrUndeclaredSchema struct {
	Name string
	Path string
	Expr Expression
}

ErrUndeclaredSchema occurs when nested object does not have schema

func (ErrUndeclaredSchema) Error

func (e ErrUndeclaredSchema) Error() string

Error returns a description of the given error as a string

func (ErrUndeclaredSchema) Prettify

func (e ErrUndeclaredSchema) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

type ErrUndeclaredSchemaInProperty

type ErrUndeclaredSchemaInProperty struct {
	Name string
	Path string
	Expr Expression
}

ErrUndeclaredSchemaInProperty occurs when nested property does not have schema

func (ErrUndeclaredSchemaInProperty) Error

Error returns a description of the given error as a string

func (ErrUndeclaredSchemaInProperty) Prettify

Prettify returns the prettified version of the given error

type ErrUndefinedSchema

type ErrUndefinedSchema struct {
	Path string
	Expr Expression
}

ErrUndefinedSchema occurs when schema is not found at path

func (ErrUndefinedSchema) Error

func (e ErrUndefinedSchema) Error() string

Error returns a description of the given error as a string

func (ErrUndefinedSchema) Prettify

func (e ErrUndefinedSchema) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

type ErrorHandle

type ErrorHandle interface {
	GetResponse() *ParameterMap
	GetStatusCode() *Property
	GetMessage() *Property
}

ErrorHandle represents a error handle object

type Evaluable

type Evaluable interface {
	Evaluate(parameters map[string]interface{}) (interface{}, error)
}

Evaluable can be evaluated (runs the expression) using provided parameters

type Expression

type Expression interface {
	Position() string
}

Expression provides information about expression.

type Flow

type Flow struct {
	*metadata.Meta
	Name    string        `json:"name,omitempty"`
	Input   *ParameterMap `json:"input,omitempty"`
	Nodes   NodeList      `json:"nodes,omitempty"`
	Output  *ParameterMap `json:"output,omitempty"`
	OnError *OnError      `json:"on_error,omitempty"`
}

Flow defines a set of calls that should be called chronologically and produces an output message. Calls could reference other resources when constructing messages. All references are strictly typed and fetched from the configured schemas.

All flows should contain a unique name. Calls are nested inside of flows and contain two labels, a unique name within the flow and the service and method to be called. A dependency reference structure is generated within the flow which allows Semaphore to figure out which calls could be called parallel to improve performance.

func (*Flow) GetForward

func (flow *Flow) GetForward() *Call

GetForward returns the proxy forward of the given flow

func (*Flow) GetInput

func (flow *Flow) GetInput() *ParameterMap

GetInput returns the input of the given flow

func (*Flow) GetMeta

func (flow *Flow) GetMeta() *metadata.Meta

GetMeta returns the metadata value object of the given flow

func (*Flow) GetName

func (flow *Flow) GetName() string

GetName returns the flow name

func (*Flow) GetNodes

func (flow *Flow) GetNodes() NodeList

GetNodes returns the calls of the given flow

func (*Flow) GetOnError

func (flow *Flow) GetOnError() *OnError

GetOnError returns the error handling of the given flow

func (*Flow) GetOutput

func (flow *Flow) GetOutput() *ParameterMap

GetOutput returns the output of the given flow

func (*Flow) GetRewrite

func (flow *Flow) GetRewrite() []Rewrite

GetRewrite returns the rewrite rules of the given flow

func (*Flow) SetNodes

func (flow *Flow) SetNodes(nodes NodeList)

SetNodes sets the given node list

type FlowInterface

type FlowInterface interface {
	GetMeta() *metadata.Meta
	GetName() string
	GetNodes() NodeList
	SetNodes(NodeList)
	GetInput() *ParameterMap
	GetOutput() *ParameterMap
	GetOnError() *OnError
	GetForward() *Call
	GetRewrite() []Rewrite
}

FlowInterface represents a proxy or flow manager.

type FlowList

type FlowList []*Flow

FlowList represents a collection of flows

func (*FlowList) Append

func (collection *FlowList) Append(list FlowList)

Append merges the incoming manifest to the existing (left) manifest

func (FlowList) Get

func (collection FlowList) Get(name string) *Flow

Get attempts to find a flow matching the given name

type FlowListInterface

type FlowListInterface []FlowInterface

FlowListInterface represents a collection of flow interfaces

func (*FlowListInterface) Append

func (collection *FlowListInterface) Append(list FlowListInterface)

Append appends the given flow list to the collection

func (FlowListInterface) Get

func (collection FlowListInterface) Get(name string) FlowInterface

Get attempts to find a flow matching the given name

type Header map[string]*Property

Header represents a collection of key values

type Message

type Message map[string]*Property

Message represents an object which keeps the original order of keys.

func (Message) Clone

func (message Message) Clone() Message

Clone the message.

func (Message) Compare

func (message Message) Compare(expected Message) error

Compare given message to the provided one returning the first mismatch.

func (Message) SortedProperties

func (message Message) SortedProperties() PropertyList

SortedProperties returns the available properties as a properties list ordered base on the properties position.

type Method

type Method struct {
	*metadata.Meta
	Comment string  `json:"comment,omitempty"`
	Name    string  `json:"name,omitempty"`
	Input   string  `json:"input,omitempty"`
	Output  string  `json:"output,omitempty"`
	Options Options `json:"options,omitempty"`
}

Method represents a service method

type Node

type Node struct {
	*metadata.Meta
	Type         NodeType      `json:"type,omitempty"`
	ID           string        `json:"id,omitempty"`
	Name         string        `json:"name,omitempty"`
	Intermediate *ParameterMap `json:"intermediate,omitempty"`
	Condition    *Condition    `json:"condition,omitempty"`
	DependsOn    Dependencies  `json:"depends_on,omitempty"`
	Call         *Call         `json:"call,omitempty"`
	Rollback     *Call         `json:"rollback,omitempty"`
	ExpectStatus []int         `json:"expect_status,omitempty"`
	OnError      *OnError      `json:"on_error,omitempty"`
}

Node represents a point inside a given flow where a request or rollback could be preformed. Nodes could be executed synchronously or asynchronously. All calls are referencing a service method, the service should match the alias defined inside the service. The request and response proto messages are used for type definitions. A call could contain the request headers, request body, rollback, and the execution type.

func (*Node) GetOnError

func (node *Node) GetOnError() *OnError

GetOnError returns the error handling for the given node

type NodeList

type NodeList []*Node

NodeList represents a collection of nodes

func (NodeList) Get

func (nodes NodeList) Get(name string) *Node

Get returns a node with the given ID

type NodeType

type NodeType string

NodeType represents the type of the given node. A type determines the purpose of the node but not the implementation.

var (
	// NodeCall is assigned when the given node is used to call a external service
	NodeCall NodeType = "call"
	// NodeCondition is assigned when the given node is used to execute a
	// conditional expression.
	NodeCondition NodeType = "condition"
	// NodeIntermediate is assigned when the node is used as a coming in
	// between nodes.
	NodeIntermediate NodeType = "intermediate"
)

type OnError

type OnError struct {
	*metadata.Meta
	Response *ParameterMap `json:"response,omitempty"`
	// Question: does it make sense to use full property here or just a Template is enough?
	Status  *Property            `json:"status,omitempty"`
	Message *Property            `json:"message,omitempty"`
	Params  map[string]*Property `json:"params,omitempty"`
}

OnError represents the variables that have to be returned if a unexpected error is returned

func (*OnError) Clone

func (err *OnError) Clone() *OnError

Clone clones the given error

func (*OnError) GetMessage

func (err *OnError) GetMessage() *Property

GetMessage returns the message property

func (*OnError) GetResponse

func (err *OnError) GetResponse() *ParameterMap

GetResponse returns the error response

func (*OnError) GetStatusCode

func (err *OnError) GetStatusCode() *Property

GetStatusCode returns the status code property

type OneOf

type OneOf []Template

OneOf is a mixed type to let the schema validate values against exactly one of the templates. Example:

OneOf{
  {Scalar: &Scalar{Type: types.String}},
  {Scalar: &Scalar{Type: types.Int32}},
  {Message: &Message{...}},
}

A given value must be one of these types: string, int32 or the message.

type Options

type Options map[string]string

Options represents a collection of options

type ParameterMap

type ParameterMap struct {
	*metadata.Meta
	DependsOn Dependencies         `json:"depends_on,omitempty"`
	Schema    string               `json:"schema,omitempty"`
	Params    map[string]*Property `json:"params,omitempty"`
	Options   Options              `json:"options,omitempty"`
	Header    Header               `json:"header,omitempty"`
	Property  *Property            `json:"property,omitempty"`
	Stack     map[string]*Property `json:"stack,omitempty"`
}

ParameterMap is the initial map of parameter names (keys) and their (templated) values (values)

func (*ParameterMap) Clone

func (parameters *ParameterMap) Clone() *ParameterMap

Clone clones the given parameter map

type Property

type Property struct {
	*metadata.Meta
	Name        string `json:"name,omitempty" yaml:"name,omitempty"`               // Name represents the name of the given property
	Path        string `json:"path,omitempty" yaml:"path,omitempty"`               // Path represents the full path to the given property
	Description string `json:"description,omitempty" yaml:"description,omitempty"` // Description holds the description of the given property used to describe its use

	Position int32 `json:"position,omitempty" yaml:"position,omitempty"` // Position of the given property (in array/object)

	Options Options    `json:"options,omitempty" yaml:"options,omitempty"` // Options holds variable options used inside single modules or components
	Expr    Expression `json:"expression,omitempty"`                       // Expr represents the position on where the given property is defined
	Raw     string     `json:"raw,omitempty"`                              // Raw holds the raw template string used to define the given property

	Label labels.Label `json:"label,omitempty" yaml:"label,omitempty"` // Label label describes the usage of a given property ex: optional

	Template `json:"template" yaml:"template"`
}

Property represents a value property.

func ParseTemplateProperty

func ParseTemplateProperty(path string, name string, value string, parsedTemplate Template) *Property

ParseTemplateProperty returns the correct property for the given (parsed)template.

func (*Property) Clone

func (property *Property) Clone() *Property

Clone makes a deep clone of the given property

func (*Property) Compare

func (property *Property) Compare(expected *Property) error

Compare checks the given property against the provided one.

func (*Property) DefaultValue

func (property *Property) DefaultValue() interface{}

DefaultValue returns the default value for a given property.

func (*Property) Define

func (property *Property) Define(expected *Property)

Define ensures that all missing nested properties are defined

func (*Property) Empty

func (property *Property) Empty() bool

Empty checks if the property has any defined type

func (*Property) ShallowClone

func (property *Property) ShallowClone() *Property

ShallowClone clones the given property but ignores the defined template and/or nested properties. This method is often used in cases where comparisons between the flow and schema are made and any defined properties are seen as defined values.

type PropertyList

type PropertyList []*Property

PropertyList represents a list of properties

func (PropertyList) Get

func (list PropertyList) Get(key string) *Property

Get attempts to return a property inside the given list with the given name

func (PropertyList) Len

func (list PropertyList) Len() int

func (PropertyList) Less

func (list PropertyList) Less(i, j int) bool

func (PropertyList) Swap

func (list PropertyList) Swap(i, j int)

type PropertyReference

type PropertyReference struct {
	*metadata.Meta
	Resource string    `json:"resource,omitempty"`
	Path     string    `json:"path,omitempty"`
	Property *Property `json:"-"`
}

PropertyReference represents a mustach template reference

func ParsePropertyReference

func ParsePropertyReference(value string) *PropertyReference

ParsePropertyReference parses the given value to a property reference.

func (*PropertyReference) Clone

func (reference *PropertyReference) Clone() *PropertyReference

Clone clones the given property reference

func (*PropertyReference) String

func (reference *PropertyReference) String() string

type Proxy

type Proxy struct {
	*metadata.Meta
	Input   *ParameterMap `json:"input,omitempty"`
	Name    string        `json:"name,omitempty"`
	Nodes   NodeList      `json:"nodes,omitempty"`
	Forward *Call         `json:"forward,omitempty"`
	Rewrite []Rewrite     `json:"rewrite,omitempty"`
	OnError *OnError      `json:"on_error,omitempty"`
}

Proxy streams the incoming request to the given service. Proxies could define calls that are executed before the request body is forwarded. A proxy forward could ideally be used for file uploads or large messages which could not be stored in memory.

func (*Proxy) GetForward

func (proxy *Proxy) GetForward() *Call

GetForward returns the proxy forward of the given flow

func (*Proxy) GetInput

func (proxy *Proxy) GetInput() *ParameterMap

GetInput returns the input of the given flow

func (*Proxy) GetMeta

func (proxy *Proxy) GetMeta() *metadata.Meta

GetMeta returns the metadata value object of the given proxy

func (*Proxy) GetName

func (proxy *Proxy) GetName() string

GetName returns the flow name

func (*Proxy) GetNodes

func (proxy *Proxy) GetNodes() NodeList

GetNodes returns the calls of the given flow

func (*Proxy) GetOnError

func (proxy *Proxy) GetOnError() *OnError

GetOnError returns the error handling of the given flow

func (*Proxy) GetOutput

func (proxy *Proxy) GetOutput() *ParameterMap

GetOutput returns the output of the given flow

func (*Proxy) GetRewrite

func (proxy *Proxy) GetRewrite() []Rewrite

GetRewrite returns the rewrite rules of the given flow

func (*Proxy) SetNodes

func (proxy *Proxy) SetNodes(nodes NodeList)

SetNodes sets the given node list

type ProxyList

type ProxyList []*Proxy

ProxyList represents a collection of proxies

func (*ProxyList) Append

func (collection *ProxyList) Append(list ProxyList)

Append merges the incoming manifest to the existing (left) manifest

func (ProxyList) Get

func (collection ProxyList) Get(name string) *Proxy

Get attempts to find a proxy matching the given name

type Repeated

type Repeated []Template

Repeated represents an array type of fixed size.

func (Repeated) Clone

func (repeated Repeated) Clone() Repeated

Clone repeated.

func (Repeated) Compare

func (repeated Repeated) Compare(expected Repeated) error

Compare given repeated to the provided one returning the first mismatch.

func (Repeated) Template

func (repeated Repeated) Template() (Template, error)

Template returns a Template for a given array. It checks the types of internal elements to detect the data type(s). Note that all the references must be resolved before calling this method.

type Rewrite

type Rewrite struct {
	Pattern  string `json:"pattern"`
	Template string `json:"template"`
}

Rewrite rules.

type Scalar

type Scalar struct {
	Default interface{} `json:"default,omitempty" yaml:"default,omitempty"`
	Type    types.Type  `json:"type,omitempty" yaml:"type,omitempty"`
}

Scalar value.

func (*Scalar) Clean

func (scalar *Scalar) Clean()

Clean fixes the type casting issue of unmarshal

func (Scalar) Clone

func (scalar Scalar) Clone() *Scalar

Clone scalar value.

func (*Scalar) Compare

func (scalar *Scalar) Compare(expected *Scalar) error

Compare the given scalar against the expected and return the first met difference as an error.

func (*Scalar) UnmarshalJSON

func (scalar *Scalar) UnmarshalJSON(data []byte) error

UnmarshalJSON corrects the 64bit data types in accordance with golang

type Schemas

type Schemas map[string]*Property

Schemas represents a map string collection of properties

func (Schemas) Append

func (objects Schemas) Append(arg Schemas)

Append appends the given objects to the objects collection

func (Schemas) Get

func (objects Schemas) Get(key string) *Property

Get attempts to return the given key from the objects collection

type Service

type Service struct {
	*metadata.Meta
	Comment            string    `json:"comment,omitempty"`
	Package            string    `json:"package,omitempty"`
	FullyQualifiedName string    `json:"fully_qualified_name,omitempty"`
	Name               string    `json:"name,omitempty"`
	Transport          string    `json:"transport,omitempty"`
	RequestCodec       string    `json:"request_codec,omitempty"`
	ResponseCodec      string    `json:"response_codec,omitempty"`
	Host               string    `json:"host,omitempty"`
	Methods            []*Method `json:"methods,omitempty"`
	Options            Options   `json:"options,omitempty"`
	Resolver           string    `json:"resolver,omitempty"`
}

Service represents a service which exposes a set of methods

func (*Service) GetMethod

func (service *Service) GetMethod(name string) *Method

GetMethod attempts to find and return a method matching the given name

type ServiceDiscoveryClient

type ServiceDiscoveryClient interface {
	Resolver(host string) (discovery.Resolver, error)
	Provider() string
}

type ServiceDiscoveryClients

type ServiceDiscoveryClients map[string]ServiceDiscoveryClient

type ServiceList

type ServiceList []*Service

ServiceList represents a collection of services

func (*ServiceList) Append

func (services *ServiceList) Append(list ServiceList)

Append appends the given services to the current services collection

func (ServiceList) Get

func (services ServiceList) Get(name string) *Service

Get attempts to find and return a flow with the given name

type Template

type Template struct {
	*metadata.Meta
	Reference *PropertyReference `json:"reference,omitempty"` // Reference represents a property reference made inside the given property

	// Only one of the following fields should be set
	Scalar   *Scalar  `json:"scalar,omitempty" yaml:"scalar,omitempty"`
	Enum     *Enum    `json:"enum,omitempty" yaml:"enum,omitempty"`
	Repeated Repeated `json:"repeated,omitempty" yaml:"repeated,omitempty"`
	Message  Message  `json:"message,omitempty" yaml:"message,omitempty"`
	OneOf    OneOf    `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
}

Template contains property schema. This is a union type (Only one field must be set).

func ParseTemplate

func ParseTemplate(ctx *broker.Context, path string, value string) (Template, error)

ParseTemplate parses the given value template, note that path is only used for debugging.

func ParseTemplateContent

func ParseTemplateContent(content string) (Template, error)

ParseTemplateContent parses the given template function.

func ParseTemplateReference

func ParseTemplateReference(value string) (Template, error)

ParseTemplateReference parses the given value as a template reference.

func (Template) Clone

func (template Template) Clone() Template

Clone internal value.

func (Template) Compare

func (template Template) Compare(expected Template) (err error)

Compare given template against the provided one returning the first mismatch.

func (Template) DefaultValue

func (template Template) DefaultValue() interface{}

Return the default value for the template (type), assuming the current type has a default.

func (*Template) Define

func (template *Template) Define(expected Template)

Define ensures that all missing nested template are defined

func (Template) ShallowClone

func (template Template) ShallowClone() Template

ShallowClone clones the given template but ignores any nested templates

func (Template) Type

func (template Template) Type() types.Type

Type returns the type of the given template.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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