elemental: go.aporeto.io/elemental Index | Files | Directories

package elemental

import "go.aporeto.io/elemental"

Package elemental provides a set of interfaces and structures used to manage a model generated from a Regolithe Specifications Set.

If you are not familiar with with Regolithe, please read https://github.com/aporeto-inc/regolithe.

Elemental is the basis of Bahamut (https://github.com/aporeto-inc/bahamut) and Manipulate (https://github.com/aporeto-inc/manipulate).

The main interface it provides is the Identifiable. This interface must be implemented by all object of a model. It allows to identify an object from its Identity (which is a name and category) and by its identifier. It also embeds the Versionable interface that allows to retrieve the current version of the model. The Identifiables interface must be implemented by lists managing a collection of Identifiable entities.

The ModelManager is an interface to perform lookup on Identities, Relationships between them and also allow to instantiate objects based on their Identity.

Elemental also contains some Request/Response structures representing various Operation on Identifiable or Identifiables as well as a bunch of validators to enforce specification constraints on attributes like max length, pattern etc. There is also an Event structure that can be used to notify clients of the the result of an Operation sent through a Request.

Elemental is mainly an abstract package and cannot really be used by itself. You must use the provided command (elegen) to generate an Elemental Model from a Regolithe Specification Set.

Index

Package Files

atomicjob.go attribute.go doc.go encoding.go error.go event.go filterparser.go filters.go filterscanner.go identity.go manager.go matcher.go matcher_options.go operations.go parameters.go push_filter.go relationships.go request.go response.go utils.go validators.go verify.go

Variables

var AllIdentity = Identity{
    Name:     "*",
    Category: "*",
}

AllIdentity represents all possible Identities.

var EmptyIdentity = Identity{
    Name:     "",
    Category: "",
}

EmptyIdentity represents an empty Identity.

var RootIdentity = Identity{
    Name:     "root",
    Category: "root",
}

RootIdentity represents an root Identity.

func AtomicJob Uses

func AtomicJob(job func() error) func(context.Context) error

AtomicJob takes a func() error and returns a func(context.Context) error. The returned function can be called as many time as you like, but only one instance of the given job can be run at the same time.

The returned function will either execute job if it it not already running or wait for the currently running job to finish. In both cases, the returned error from the job will be forwareded and returned to every caller.

You must pass a context.Context to the returned function so you can control how much time you are willing to wait for the job to complete.

If you wish to change some external state from within the job function, it is your responsibility to ensure everything is thread safe.

func BackportUnexposedFields Uses

func BackportUnexposedFields(src, dest AttributeSpecifiable)

BackportUnexposedFields copy the values of unexposed fields from src to dest.

func Convert Uses

func Convert(from EncodingType, to EncodingType, data []byte) ([]byte, error)

Convert converts from one EncodingType to another

func Decode Uses

func Decode(encoding EncodingType, data []byte, dest interface{}) error

Decode decodes the given data using an appropriate decoder chosen from the given contentType.

func Encode Uses

func Encode(encoding EncodingType, obj interface{}) ([]byte, error)

Encode encodes the given object using an appropriate encoder chosen from the given acceptType.

func EncodingFromHeaders Uses

func EncodingFromHeaders(header http.Header) (read EncodingType, write EncodingType, err error)

EncodingFromHeaders returns the read (Content-Type) and write (Accept) encoding from the given http.Header.

func IsErrorWithCode Uses

func IsErrorWithCode(err error, code int) bool

IsErrorWithCode returns true if the given error is an elemental.Error or elemental.Errors with the status set to the given code.

func IsOperationAllowed Uses

func IsOperationAllowed(registry RelationshipsRegistry, i Identity, pid Identity, op Operation) bool

IsOperationAllowed returns true if given operatation on the given identity with the given parent is allowed.

func IsValidationError Uses

func IsValidationError(err error, title string, attribute string) bool

IsValidationError returns true if the given error is a validation error with the given title for the given attribute.

func IsZero Uses

func IsZero(o interface{}) bool

IsZero returns true if the given value is set to its Zero value.

func MatchesFilter Uses

func MatchesFilter(identifiable AttributeSpecifiable, filter *Filter, opts ...MatcherOption) (bool, error)

MatchesFilter determines whether an identity matches a filter

func RegisterSupportedAcceptType Uses

func RegisterSupportedAcceptType(mimetype string)

RegisterSupportedAcceptType registers a new media type that elemental should support for Accept. Note that this needs external intervention to handle decoding.

func RegisterSupportedContentType Uses

func RegisterSupportedContentType(mimetype string)

RegisterSupportedContentType registers a new media type that elemental should support for Content-Type. Note that this needs external intervention to handle encoding.

func RemoveZeroValues Uses

func RemoveZeroValues(obj interface{})

RemoveZeroValues reset all pointer fields that are pointing to a zero value to nil

func ResetDefaultForZeroValues Uses

func ResetDefaultForZeroValues(obj interface{})

ResetDefaultForZeroValues reset the default value from the specification when a field is Zero. If the given object is not an elemental.AttributeSpecifiable this function does nothing.

func ResetMaps Uses

func ResetMaps(v reflect.Value)

ResetMaps recursively empty all kinds of maps in the given reflect.Value.

func ResetSecretAttributesValues Uses

func ResetSecretAttributesValues(obj interface{})

ResetSecretAttributesValues will reset any attributes marked as `secret` in the given obj if it is an elemental.Identifiable or an elemental.Identifiables. The given Identifiables must implement the elemental.AttributeSpecifiable interface or this function will have no effect.

If you pass anything else, this function does nothing.

func ValidateAdvancedSpecification Uses

func ValidateAdvancedSpecification(obj AttributeSpecifiable, pristine AttributeSpecifiable, op Operation) error

ValidateAdvancedSpecification verifies advanced specifications attributes like ReadOnly and CreationOnly.

For instance, it will check if the given Manipulable has field marked as readonly, that it has not changed according to the db.

func ValidateFloatInList Uses

func ValidateFloatInList(attribute string, value float64, enums []float64) error

ValidateFloatInList validates if the string is in the list.

func ValidateFloatInMap Uses

func ValidateFloatInMap(attribute string, value float64, enums map[float64]interface{}) error

ValidateFloatInMap validates if the string is in the list.

func ValidateIntInList Uses

func ValidateIntInList(attribute string, value int, enums []int) error

ValidateIntInList validates if the string is in the list.

func ValidateIntInMap Uses

func ValidateIntInMap(attribute string, value int, enums map[int]interface{}) error

ValidateIntInMap validates if the string is in the list.

func ValidateMaximumFloat Uses

func ValidateMaximumFloat(attribute string, value float64, max float64, exclusive bool) error

ValidateMaximumFloat validates a float against a maximum value.

func ValidateMaximumInt Uses

func ValidateMaximumInt(attribute string, value int, max int, exclusive bool) error

ValidateMaximumInt validates a integer against a maximum value.

func ValidateMaximumLength Uses

func ValidateMaximumLength(attribute string, value string, max int, exclusive bool) error

ValidateMaximumLength validates the maximum length of a string.

func ValidateMinimumFloat Uses

func ValidateMinimumFloat(attribute string, value float64, min float64, exclusive bool) error

ValidateMinimumFloat validates a float against a maximum value.

func ValidateMinimumInt Uses

func ValidateMinimumInt(attribute string, value int, min int, exclusive bool) error

ValidateMinimumInt validates a integer against a maximum value.

func ValidateMinimumLength Uses

func ValidateMinimumLength(attribute string, value string, min int, exclusive bool) error

ValidateMinimumLength validates the minimum length of a string.

func ValidatePattern Uses

func ValidatePattern(attribute string, value string, pattern string, message string, required bool) error

ValidatePattern validates a string against a regular expression.

func ValidateRequiredExternal Uses

func ValidateRequiredExternal(attribute string, value interface{}) error

ValidateRequiredExternal validates if the given value is null or not

func ValidateRequiredFloat Uses

func ValidateRequiredFloat(attribute string, value float64) error

ValidateRequiredFloat validates is the int is set to 0.

func ValidateRequiredInt Uses

func ValidateRequiredInt(attribute string, value int) error

ValidateRequiredInt validates is the int is set to 0.

func ValidateRequiredString Uses

func ValidateRequiredString(attribute string, value string) error

ValidateRequiredString validates if the string is empty.

func ValidateRequiredTime Uses

func ValidateRequiredTime(attribute string, value time.Time) error

ValidateRequiredTime validates if the time is empty.

func ValidateStringInList Uses

func ValidateStringInList(attribute string, value string, enums []string, autogenerated bool) error

ValidateStringInList validates if the string is in the list.

func ValidateStringInMap Uses

func ValidateStringInMap(attribute string, value string, enums map[string]interface{}, autogenerated bool) error

ValidateStringInMap validates if the string is in the list.

type AttributeEncryptable Uses

type AttributeEncryptable interface {
    EncryptAttributes(encrypter AttributeEncrypter) error
    DecryptAttributes(encrypter AttributeEncrypter) error
}

AttributeEncryptable is the interface of on object that has encryptable

type AttributeEncrypter Uses

type AttributeEncrypter interface {

    // EncryptString encrypts the given string and returns the encrypted version.
    EncryptString(string) (string, error)

    // DecryptString decrypts the given string and returns the encrypted version.
    DecryptString(string) (string, error)
}

AttributeEncrypter is the interface that must be implement to manage encrypted attributes.

func NewAESAttributeEncrypter Uses

func NewAESAttributeEncrypter(passphrase string) (AttributeEncrypter, error)

NewAESAttributeEncrypter returns a new elemental.AttributeEncrypter implementing AES encryption.

type AttributeSpecifiable Uses

type AttributeSpecifiable interface {

    // SpecificationForAttribute returns the AttributeSpecification for
    // given attribute name
    SpecificationForAttribute(string) AttributeSpecification

    // AttributeSpecifications returns all the AttributeSpecification mapped by
    // attribute name
    AttributeSpecifications() map[string]AttributeSpecification

    // ValueForAttribute returns the value for the given attribute
    ValueForAttribute(name string) interface{}
}

An AttributeSpecifiable is the interface an object must implement in order to access specification of its attributes.

type AttributeSpecification Uses

type AttributeSpecification struct {

    // AllowedChars is a regexp that will be used to validate
    // what value a string attribute can take.
    //
    // This is enforced by elemental.
    AllowedChars string

    // AllowedChoices is a list of possible values for an attribute.
    //
    // This is enforced by elemental.
    AllowedChoices []string

    // Autogenerated defines if the attribute is autogenerated by the server.
    // It can be used in conjunction with ReadOnly.
    //
    // This is not enforced by elemental. You must write your own business logic to honor this.
    Autogenerated bool

    // Availability is reserved for later use.
    Availability string

    // ConvertedName contains the name after local conversion.
    ConvertedName string

    // Channel is reserved for later use.
    Channel string

    // CreationOnly defines if the attribute can be set only during creation.
    //
    // This is not enforced by elemental. You must write your own business logic to honor this.
    CreationOnly bool

    // DefaultValue holds the default value declared in specification.
    DefaultValue interface{}

    // Deprecated defines if the attribute is deprecated.
    Deprecated bool

    // Description contains the description of the attribute.
    Description string

    // Exposed defines if the attribute is exposed through the north bound API.
    Exposed bool

    // Filterable defines if it is possible to filter based on this attribute.
    //
    // This is not enforced by elemental. You must write your own business logic to honor this.
    Filterable bool

    // ForeignKey defines if the attribute is a foreign key.
    ForeignKey bool

    // Getter defines if the attribute needs to define a getter method.
    // This is useful if you can to define an Interface based on this attribute.
    Getter bool

    // Identifier defines if the attribute is used the access key from the
    // northbound API.
    Identifier bool

    // Index defines if the attribute is indexed or not.
    //
    // This is not enforced by elemental. You must write your own business logic to honor this.
    Index bool

    // MaxLength defines what is the maximun length of the attribute.
    // This only makes sense if the type is a string.
    //
    // This is enforced by elemental.
    MaxLength uint

    // MaxValue defines what is the maximun value of the attribute.
    // This only makes sense if the type has a numeric type.
    //
    // This is enforced by elemental.
    MaxValue float64

    // MinLength defines what is the minimum length of the attribute.
    // This only makes sense if the type is a string.
    //
    // This is enforced by elemental.
    MinLength uint

    // MinValue defines what is the minimum value of the attribute.
    // This only makes sense if the type has a numeric type.
    //
    // This is enforced by elemental.
    MinValue float64

    // Name defines what is the name of the attribute.
    // This will be the raw Monolithe Specification name, without
    // Go translation.
    Name string

    // Orderable defines if it is possible to order based on the value of this attribute.
    //
    // This is not enforced by elemental. You must write your own business logic to honor this.
    Orderable bool

    // PrimaryKey defines if the attribute is used as a primary key.
    PrimaryKey bool

    // ReadOnly defines if the attribute is read only.
    //
    // This is not enforced by elemental. You must write your own business logic to honor this.
    ReadOnly bool

    // Required defines is the attribute must be set or not.
    //
    // This is enforced by elemental.
    Required bool

    // Secret defines if the attribute is secret.
    // This is useful if you can to define perform sanity check on this field to be sure it
    // is not sent for instance.
    Secret bool

    // Setter defines if the attribute needs to define a setter method.
    // This is useful if you can to define an Interface based on this attribute.
    Setter bool

    // Stored defines if the attribute will be stored in the northbound API.
    //
    // If this is true, the backend tags will be generated by Monolithe.
    Stored bool

    // SubType defines the Monolithe Subtype.
    SubType string

    // Transient defines if the attributes is transient or not.
    //
    // This is not enforced by elemental. You must write your own business logic to honor this.
    Transient bool

    // Type defines the raw Monolithe type.
    Type string

    // Encrypted defines if the attribute needs encryption.
    Encrypted bool
}

An AttributeSpecification represents all the metadata of an attribute.

This information is coming from the Monolithe Specifications.

type Decoder Uses

type Decoder interface {
    Decode(dst interface{}) error
    Encodable
}

A Decoder is an Encodable that can be decoded.

type DefaultOrderer Uses

type DefaultOrderer interface {

    // Default order returns the keys that can be used for default ordering.
    DefaultOrder() []string
}

DefaultOrderer is the interface of an object that has default ordering fields.

type Documentable Uses

type Documentable interface {
    Doc() string
}

A Documentable is an object that can be documented.

type Encodable Uses

type Encodable interface {
    GetEncoding() EncodingType
}

An Encodable is the interface of objects that can hold encoding information.

type Encoder Uses

type Encoder interface {
    Encode(obj interface{}) (err error)
    Encodable
}

A Encoder is an Encodable that can be encoded.

type EncodingType Uses

type EncodingType string

An EncodingType represents one type of data encoding

const (
    EncodingTypeJSON    EncodingType = "application/json"
    EncodingTypeMSGPACK EncodingType = "application/msgpack"
)

Various values for EncodingType.

type Error Uses

type Error struct {
    Code        int         `msgpack:"code" json:"code"`
    Description string      `msgpack:"description" json:"description"`
    Subject     string      `msgpack:"subject" json:"subject"`
    Title       string      `msgpack:"title" json:"title"`
    Data        interface{} `msgpack:"data" json:"data"`
    Trace       string      `msgpack:"trace" json:"trace"`
}

An Error represents a computational error.

They can be encoded and sent back to the clients.

func NewError Uses

func NewError(title, description, subject string, code int) Error

NewError returns a new Error.

func NewErrorWithData Uses

func NewErrorWithData(title, description, subject string, code int, data interface{}) Error

NewErrorWithData returns a new Error with the given opaque data.

func (Error) Error Uses

func (e Error) Error() string

type Errors Uses

type Errors []Error

Errors represents a list of Error.

func DecodeErrors Uses

func DecodeErrors(data []byte) (Errors, error)

DecodeErrors decodes the given bytes into a en elemental.Errors.

func NewErrors Uses

func NewErrors(errors ...error) Errors

NewErrors creates a new Errors.

func (Errors) Append Uses

func (e Errors) Append(errs ...error) Errors

Append returns returns a copy of the receiver containing also the given errors.

func (Errors) Code Uses

func (e Errors) Code() int

Code returns the code of the first error code in the Errors.

func (Errors) Error Uses

func (e Errors) Error() string

func (Errors) Trace Uses

func (e Errors) Trace(id string) Errors

Trace returns Errors with all inside Error marked with the given trace ID.

type Event Uses

type Event struct {
    RawData   []byte          `msgpack:"entity" json:"-"`
    JSONData  json.RawMessage `msgpack:"-" json:"entity"`
    Identity  string          `msgpack:"identity" json:"identity"`
    Type      EventType       `msgpack:"type" json:"type"`
    Timestamp time.Time       `msgpack:"timestamp" json:"timestamp"`
    Encoding  EncodingType    `msgpack:"encoding" json:"encoding"`
}

An Event represents a computational event.

func NewEvent Uses

func NewEvent(t EventType, o Identifiable) *Event

NewEvent returns a new Event.

func NewEventWithEncoding Uses

func NewEventWithEncoding(t EventType, o Identifiable, encoding EncodingType) *Event

NewEventWithEncoding returns a new Event using the given encoding

func (*Event) Convert Uses

func (e *Event) Convert(encoding EncodingType) error

Convert converts the internal encoded data to the given encoding.

func (*Event) Decode Uses

func (e *Event) Decode(dst interface{}) error

Decode decodes the data into the given destination.

func (*Event) Duplicate Uses

func (e *Event) Duplicate() *Event

Duplicate creates a copy of the event.

func (*Event) Entity Uses

func (e *Event) Entity() []byte

Entity returns the byte encoded entity.

func (*Event) GetEncoding Uses

func (e *Event) GetEncoding() EncodingType

GetEncoding returns the encoding used to encode the entity.

func (*Event) String Uses

func (e *Event) String() string

type EventType Uses

type EventType string

EventType is the type of an event.

const (
    // EventCreate is the type of creation event.
    EventCreate EventType = "create"

    // EventUpdate is the type of update event.
    EventUpdate EventType = "update"

    // EventDelete is the type of delete event.
    EventDelete EventType = "delete"
)

type Events Uses

type Events []*Event

An Events represents a list of Event.

func NewEvents Uses

func NewEvents(events ...*Event) Events

NewEvents retutns a new Events.

type Filter Uses

type Filter struct {
    // contains filtered or unexported fields
}

Filter is a filter struct which can be used with Cassandra

func NewFilter Uses

func NewFilter() *Filter

NewFilter returns a new filter.

func NewFilterFromString Uses

func NewFilterFromString(filter string) (*Filter, error)

NewFilterFromString returns a new filter computed from the given string.

func (*Filter) And Uses

func (f *Filter) And(filters ...*Filter) FilterKeyComposer

And adds a new sub filter to FilterComposer.

func (*Filter) AndFilters Uses

func (f *Filter) AndFilters() SubFilters

AndFilters returns the current and sub filters.

func (*Filter) Comparators Uses

func (f *Filter) Comparators() FilterComparators

Comparators returns the current comparators.

func (*Filter) Contains Uses

func (f *Filter) Contains(values ...interface{}) FilterKeyComposer

Contains adds a contains comparator to the FilterComposer.

func (*Filter) Done Uses

func (f *Filter) Done() *Filter

Done terminates the filter composition and returns the *Filter.

func (*Filter) Equals Uses

func (f *Filter) Equals(value interface{}) FilterKeyComposer

Equals adds a an equality comparator to the FilterComposer.

func (*Filter) Exists Uses

func (f *Filter) Exists() FilterKeyComposer

Exists adds an exists comparator to the FilterComposer.

func (*Filter) GreaterOrEqualThan Uses

func (f *Filter) GreaterOrEqualThan(value interface{}) FilterKeyComposer

GreaterOrEqualThan adds a greater than (inclusive) comparator to the FilterComposer.

func (*Filter) GreaterThan Uses

func (f *Filter) GreaterThan(value interface{}) FilterKeyComposer

GreaterThan adds a greater than (exclusive) comparator to the FilterComposer.

func (*Filter) In Uses

func (f *Filter) In(values ...interface{}) FilterKeyComposer

In adds a in comparator to the FilterComposer.

func (*Filter) Keys Uses

func (f *Filter) Keys() FilterKeys

Keys returns the current keys.

func (*Filter) LesserOrEqualThan Uses

func (f *Filter) LesserOrEqualThan(value interface{}) FilterKeyComposer

LesserOrEqualThan adds a lesser than (inclusive) comparator to the FilterComposer.

func (*Filter) LesserThan Uses

func (f *Filter) LesserThan(value interface{}) FilterKeyComposer

LesserThan adds a lesser than (exclusive) comparator to the FilterComposer.

func (*Filter) Matches Uses

func (f *Filter) Matches(values ...interface{}) FilterKeyComposer

Matches adds a match comparator to the FilterComposer.

func (*Filter) NotContains Uses

func (f *Filter) NotContains(values ...interface{}) FilterKeyComposer

NotContains adds a contains comparator to the FilterComposer.

func (*Filter) NotEquals Uses

func (f *Filter) NotEquals(value interface{}) FilterKeyComposer

NotEquals adds a an non equality comparator to the FilterComposer.

func (*Filter) NotExists Uses

func (f *Filter) NotExists() FilterKeyComposer

NotExists adds an not exist comparator to the FilterComposer.

func (*Filter) NotIn Uses

func (f *Filter) NotIn(values ...interface{}) FilterKeyComposer

NotIn adds a not in comparator to the FilterComposer.

func (*Filter) Operators Uses

func (f *Filter) Operators() FilterOperators

Operators returns the current operators.

func (*Filter) Or Uses

func (f *Filter) Or(filters ...*Filter) FilterKeyComposer

Or adds a new sub filter to FilterComposer.

func (*Filter) OrFilters Uses

func (f *Filter) OrFilters() SubFilters

OrFilters returns the current ors sub filters.

func (*Filter) String Uses

func (f *Filter) String() string

func (*Filter) Values Uses

func (f *Filter) Values() FilterValues

Values returns the current values.

func (*Filter) WithKey Uses

func (f *Filter) WithKey(key string) FilterValueComposer

WithKey adds a key to FilterComposer.

type FilterComparator Uses

type FilterComparator int

An FilterComparator is the type of a operator used by a filter.

const (
    EqualComparator FilterComparator = iota
    NotEqualComparator
    GreaterComparator
    GreaterOrEqualComparator
    LesserComparator
    LesserOrEqualComparator
    InComparator
    NotInComparator
    ContainComparator
    NotContainComparator
    MatchComparator
    NotMatchComparator
    ExistsComparator
    NotExistsComparator
)

Comparators represent various comparison operations.

type FilterComparators Uses

type FilterComparators []FilterComparator

FilterComparators are a list of FilterOperator.

type FilterKeyComposer Uses

type FilterKeyComposer interface {
    WithKey(string) FilterValueComposer

    And(...*Filter) FilterKeyComposer
    Or(...*Filter) FilterKeyComposer

    Done() *Filter
}

FilterKeyComposer composes a filter.

func NewFilterComposer Uses

func NewFilterComposer() FilterKeyComposer

NewFilterComposer returns a FilterComposer.

type FilterKeys Uses

type FilterKeys []string

FilterKeys represents a list of FilterKey.

type FilterOperator Uses

type FilterOperator int

An FilterOperator is the type of a operator used by a filter.

const (
    AndOperator FilterOperator = iota
    OrFilterOperator
    AndFilterOperator
)

Operators represent various operators.

type FilterOperators Uses

type FilterOperators []FilterOperator

FilterOperators are a list of FilterOperator.

type FilterParser Uses

type FilterParser struct {
    // contains filtered or unexported fields
}

FilterParser represents a Parser

func NewFilterParser Uses

func NewFilterParser(input string) *FilterParser

NewFilterParser returns an instance of FilterParser for the given input

func (*FilterParser) Parse Uses

func (p *FilterParser) Parse() (*Filter, error)

Parse parses the input string and returns a new Filter.

type FilterValue Uses

type FilterValue []interface{}

FilterValue represents a filter value.

type FilterValueComposer Uses

type FilterValueComposer interface {
    Equals(interface{}) FilterKeyComposer
    NotEquals(interface{}) FilterKeyComposer
    GreaterOrEqualThan(interface{}) FilterKeyComposer
    GreaterThan(interface{}) FilterKeyComposer
    LesserOrEqualThan(interface{}) FilterKeyComposer
    LesserThan(interface{}) FilterKeyComposer
    In(...interface{}) FilterKeyComposer
    NotIn(...interface{}) FilterKeyComposer
    Contains(...interface{}) FilterKeyComposer
    NotContains(...interface{}) FilterKeyComposer
    Matches(...interface{}) FilterKeyComposer
    Exists() FilterKeyComposer
    NotExists() FilterKeyComposer
}

FilterValueComposer adds values and operators.

type FilterValues Uses

type FilterValues [][]interface{}

FilterValues represents a list of FilterValue.

type Identifiable Uses

type Identifiable interface {

    // Identity returns the Identity of the of the receiver.
    Identity() Identity

    // Identifier returns the unique identifier of the of the receiver.
    Identifier() string

    // SetIdentifier sets the unique identifier of the of the receiver.
    SetIdentifier(string)

    Versionable
}

An Identifiable is the interface that Elemental objects must implement.

type Identifiables Uses

type Identifiables interface {
    Identity() Identity
    List() IdentifiablesList
    Copy() Identifiables
    Append(...Identifiable) Identifiables
    Versionable
}

Identifiables is the interface of a list of Identifiable that can returns the Identity of the objects it contains.

type IdentifiablesList Uses

type IdentifiablesList []Identifiable

An IdentifiablesList is a list of objects implementing the Identifiable interface.

type Identity Uses

type Identity struct {
    Name     string `msgpack:"name" json:"name"`
    Category string `msgpack:"category" json:"category"`
    Private  bool   `msgpack:"-" json:"-"`
    Package  string `msgpack:"-" json:"-"`
}

An Identity is a structure that contains the necessary information about an Identifiable. The Name is usually the singular form of the Category.

For instance, "cat" and "cats".

func MakeIdentity Uses

func MakeIdentity(name, category string) Identity

MakeIdentity returns a new Identity.

func (Identity) IsEmpty Uses

func (i Identity) IsEmpty() bool

IsEmpty checks if the identity is empty.

func (Identity) IsEqual Uses

func (i Identity) IsEqual(identity Identity) bool

IsEqual checks if the given identity is equal to the receiver.

func (Identity) String Uses

func (i Identity) String() string

String returns the string representation of the identity.

type MatcherOption Uses

type MatcherOption func(*matchConfig)

MatcherOption represents the type for the options that can be passed to the helper `MatchesFilter` which can be used to alter the matching behaviour

type ModelManager Uses

type ModelManager interface {

    // Identifiable returns an Identifiable with the given identity.
    Identifiable(Identity) Identifiable

    // SparseIdentifiable returns a SparseIdentifiable with the given identity.
    SparseIdentifiable(Identity) SparseIdentifiable

    // IdentifiableFromString returns an Identifiable from the given
    // string. The string can be an Identity name, category or alias.
    IdentifiableFromString(string) Identifiable

    // Identifiables returns an Identifiables with the given identity.
    Identifiables(Identity) Identifiables

    // SparseIdentifiables returns an Identifiables with the given identity.
    SparseIdentifiables(Identity) SparseIdentifiables

    // IdentifiablesFrom returns an Identifiables from the given
    // string. The string can be an Identity name, category or alias.
    IdentifiablesFromString(string) Identifiables

    // IdentityFromName returns the Identity from the given name.
    IdentityFromName(string) Identity

    // IdentityFromCategory returns the Identity from the given category.
    IdentityFromCategory(string) Identity

    // IdentityFromAlias returns the Identity from the given alias.
    IdentityFromAlias(string) Identity

    // IdentityFromAny returns the Identity from the given name, category or alias.
    IdentityFromAny(string) Identity

    // IndexesForIdentity returns the indexes of the given Identity.
    Indexes(Identity) [][]string

    // Relationships return the model's elemental.RelationshipsRegistry.
    Relationships() RelationshipsRegistry
}

An ModelManager is the interface that allows to search Identities and create Identifiable and Identifiables from Identities.

type Operation Uses

type Operation string

Operation represents an operation to apply on an Identifiable from a Request.

const (
    OperationRetrieveMany Operation = "retrieve-many"
    OperationRetrieve     Operation = "retrieve"
    OperationCreate       Operation = "create"
    OperationUpdate       Operation = "update"
    OperationDelete       Operation = "delete"
    OperationPatch        Operation = "patch"
    OperationInfo         Operation = "info"

    OperationEmpty Operation = ""
)

Here are the existing Operations.

func ParseOperation Uses

func ParseOperation(op string) (Operation, error)

ParseOperation parses the given string as an Operation.

type Parameter Uses

type Parameter struct {
    // contains filtered or unexported fields
}

A Parameter represent one parameter that can be sent with a query.

func NewParameter Uses

func NewParameter(ptype ParameterType, values ...interface{}) Parameter

NewParameter returns a new Parameter.

func (Parameter) BoolValue Uses

func (p Parameter) BoolValue() bool

BoolValue returns the value as a bool.

func (Parameter) BoolValues Uses

func (p Parameter) BoolValues() []bool

BoolValues returns all the values as a []bool.

func (Parameter) DurationValue Uses

func (p Parameter) DurationValue() time.Duration

DurationValue returns the value as a time.Duration.

func (Parameter) DurationValues Uses

func (p Parameter) DurationValues() []time.Duration

DurationValues returns all the values as a []time.Duration.

func (Parameter) FloatValue Uses

func (p Parameter) FloatValue() float64

FloatValue returns the value as a float.

func (Parameter) FloatValues Uses

func (p Parameter) FloatValues() []float64

FloatValues returns all the values as a []float64.

func (Parameter) IntValue Uses

func (p Parameter) IntValue() int

IntValue returns the value as a int.

func (Parameter) IntValues Uses

func (p Parameter) IntValues() []int

IntValues returns all the values as a []int.

func (Parameter) StringValue Uses

func (p Parameter) StringValue() string

StringValue returns the value as a string.

func (Parameter) StringValues Uses

func (p Parameter) StringValues() []string

StringValues returns all the values as a []string.

func (Parameter) TimeValue Uses

func (p Parameter) TimeValue() time.Time

TimeValue returns the value as a time.Time.

func (Parameter) TimeValues Uses

func (p Parameter) TimeValues() []time.Time

TimeValues returns all the values as a []time.Time.

func (Parameter) Values Uses

func (p Parameter) Values() []interface{}

Values returns all the parsed values

type ParameterDefinition Uses

type ParameterDefinition struct {
    Name           string
    Type           ParameterType
    AllowedChoices []string
    DefaultValue   string
    Multiple       bool
}

A ParameterDefinition represent a parameter definition that can be transformed into a Parameter.

func ParametersForOperation Uses

func ParametersForOperation(registry RelationshipsRegistry, i Identity, pid Identity, op Operation) []ParameterDefinition

ParametersForOperation returns the parameters defined for the retrieve operation on the given identity.

func (*ParameterDefinition) Parse Uses

func (p *ParameterDefinition) Parse(values []string) (*Parameter, error)

Parse parses the given value against the parameter definition

type ParameterType Uses

type ParameterType string

ParameterType represents the various type for a parameter.

const (
    ParameterTypeString   ParameterType = "string"
    ParameterTypeInt      ParameterType = "integer"
    ParameterTypeFloat    ParameterType = "float"
    ParameterTypeBool     ParameterType = "boolean"
    ParameterTypeEnum     ParameterType = "enum"
    ParameterTypeTime     ParameterType = "time"
    ParameterTypeDuration ParameterType = "duration"
)

Various values for ParameterType.

type Parameters Uses

type Parameters map[string]Parameter

Parameters represents a set of Parameters.

func (Parameters) Get Uses

func (p Parameters) Get(name string) Parameter

Get returns the Parameter with the given name

func (Parameters) Validate Uses

func (p Parameters) Validate(r ParametersRequirement) error

Validate validates if the Parameters matches the given requirement.

type ParametersRequirement Uses

type ParametersRequirement struct {
    // contains filtered or unexported fields
}

A ParametersRequirement represents a list of ands of list of ors that must be passed together.

func NewParametersRequirement Uses

func NewParametersRequirement(match [][][]string) ParametersRequirement

NewParametersRequirement returns a new ParametersRequirement.

func (ParametersRequirement) String Uses

func (r ParametersRequirement) String() string

type Patchable Uses

type Patchable interface {

    // Patch patches the receiver using the given SparseIdentifiable.
    Patch(SparseIdentifiable)
}

A Patchable the interface of an object that can be patched.

type PlainIdentifiable Uses

type PlainIdentifiable interface {

    // ToSparse returns a sparsed version of the object.
    ToSparse(...string) SparseIdentifiable

    Identifiable
}

A PlainIdentifiable is the interface of an object that can return a sparse version of itself.

type PlainIdentifiables Uses

type PlainIdentifiables interface {

    // ToSparse returns a sparsed version of the object.
    ToSparse(...string) Identifiables

    Identifiables
}

A PlainIdentifiables is the interface of an object that can return a sparse version of itself.

type PushFilter Uses

type PushFilter struct {
    Identities map[string][]EventType `msgpack:"identities" json:"identities"`
    Params     url.Values             `msgpack:"parameters" json:"parameters"`
}

A PushFilter represents an abstract filter for filtering out push notifications.

func NewPushFilter Uses

func NewPushFilter() *PushFilter

NewPushFilter returns a new PushFilter.

func (*PushFilter) Duplicate Uses

func (f *PushFilter) Duplicate() *PushFilter

Duplicate duplicates the PushFilter.

func (*PushFilter) FilterIdentity Uses

func (f *PushFilter) FilterIdentity(identityName string, eventTypes ...EventType)

FilterIdentity adds the given identity for the given eventTypes in the PushFilter.

func (*PushFilter) IsFilteredOut Uses

func (f *PushFilter) IsFilteredOut(identityName string, eventType EventType) bool

IsFilteredOut returns true if the given Identity is not part of the PushFilter.

func (*PushFilter) Parameters Uses

func (f *PushFilter) Parameters() url.Values

Parameters returns a copy of all the parameters.

func (*PushFilter) SetParameter Uses

func (f *PushFilter) SetParameter(key string, values ...string)

SetParameter sets the values of the parameter with the given key.

func (*PushFilter) String Uses

func (f *PushFilter) String() string

type Relationship Uses

type Relationship struct {
    Type string

    Retrieve     map[string]*RelationshipInfo
    RetrieveMany map[string]*RelationshipInfo
    Info         map[string]*RelationshipInfo
    Create       map[string]*RelationshipInfo
    Update       map[string]*RelationshipInfo
    Delete       map[string]*RelationshipInfo
    Patch        map[string]*RelationshipInfo
}

A Relationship describes the hierarchical relationship of the models.

type RelationshipInfo Uses

type RelationshipInfo struct {
    Deprecated         bool
    Parameters         []ParameterDefinition
    RequiredParameters ParametersRequirement
}

A RelationshipInfo describe the various meta information of a relationship.

func RelationshipInfoForOperation Uses

func RelationshipInfoForOperation(registry RelationshipsRegistry, i Identity, pid Identity, op Operation) *RelationshipInfo

RelationshipInfoForOperation returns the relationship info for the given identity, parent identity and operation.

type RelationshipsRegistry Uses

type RelationshipsRegistry map[Identity]*Relationship

A RelationshipsRegistry maintains the relationship for Identities.

type Request Uses

type Request struct {
    RequestID            string
    Namespace            string
    Recursive            bool
    Operation            Operation
    Identity             Identity
    Order                []string
    ObjectID             string
    ParentIdentity       Identity
    ParentID             string
    Data                 []byte
    Parameters           Parameters
    Headers              http.Header
    Username             string
    Password             string
    Page                 int
    PageSize             int
    After                string
    Limit                int
    OverrideProtection   bool
    Version              int
    ExternalTrackingID   string
    ExternalTrackingType string
    ContentType          EncodingType
    Accept               EncodingType

    Metadata           map[string]interface{}
    ClientIP           string
    TLSConnectionState *tls.ConnectionState
    // contains filtered or unexported fields
}

A Request represents an abstract request on an elemental model.

func NewRequest Uses

func NewRequest() *Request

NewRequest returns a new Request.

func NewRequestFromHTTPRequest Uses

func NewRequestFromHTTPRequest(req *http.Request, manager ModelManager) (*Request, error)

NewRequestFromHTTPRequest returns a new Request from the given http.Request.

func (*Request) Decode Uses

func (r *Request) Decode(dst interface{}) error

Decode decodes the data into the given destination.

func (*Request) Duplicate Uses

func (r *Request) Duplicate() *Request

Duplicate duplicates the Request.

func (*Request) GetEncoding Uses

func (r *Request) GetEncoding() EncodingType

GetEncoding returns the encoding used to encode the body.

func (*Request) HTTPRequest Uses

func (r *Request) HTTPRequest() *http.Request

HTTPRequest returns the native http.Request, if any.

func (*Request) String Uses

func (r *Request) String() string

type Response Uses

type Response struct {
    StatusCode int
    Data       []byte
    Count      int
    Total      int
    Next       string
    Messages   []string
    Redirect   string
    RequestID  string
    Request    *Request
}

A Response contains the response from a Request.

func NewResponse Uses

func NewResponse(req *Request) *Response

NewResponse returns a new Response

func (*Response) Encode Uses

func (r *Response) Encode(obj interface{}) (err error)

Encode encodes the given oject into the response.

func (*Response) GetEncoding Uses

func (r *Response) GetEncoding() EncodingType

GetEncoding returns the encoding used to encode the entity.

type SparseIdentifiable Uses

type SparseIdentifiable interface {

    // ToPlain returns the full version of the object.
    ToPlain() PlainIdentifiable

    Identifiable
}

A SparseIdentifiable is the interface of an object that can return a full version of itself.

type SparseIdentifiables Uses

type SparseIdentifiables interface {

    // ToPlain returns the full version of the object.
    ToPlain() IdentifiablesList

    Identifiables
}

A SparseIdentifiables is the interface of an object that can return a full version of itself.

type SubFilter Uses

type SubFilter []*Filter

SubFilter is the type of subfilter

type SubFilters Uses

type SubFilters []SubFilter

SubFilters is is a list SubFilter,

type Validatable Uses

type Validatable interface {
    Validate() error
}

A Validatable is the interface for objects that can be validated.

type Versionable Uses

type Versionable interface {
    Version() int
}

A Versionable is an object that can be versioned.

Directories

PathSynopsis
internalPackage internal is a generated GoMock package.
test/model

Package elemental imports 24 packages (graph) and is imported by 17 packages. Updated 2019-11-15. Refresh now. Tools for package owners.