Categorygithub.com/codingjzy/manipulate
modulepackage
0.0.2
Repository: https://github.com/codingjzy/manipulate.git
Documentation: pkg.go.dev

# README

Manipulate

codecov

Package manipulate provides everything needed to perform CRUD operations on an elemental based data model.

The main interface is Manipulator. This interface provides various methods for creation, modification, retrieval and so on.

A Manipulator works with elemental.Identifiable.

The storage engine used by a Manipulator is abstracted. By default manipulate provides implementations for Mongo, ReST HTTP, Websocket and a Memory backed datastore. You can of course implement Your own storage implementation.

Each method of a Manipulator is taking a manipulate.Context as argument. The context is used to pass additional informations like a Filter, or some Parameters.

Example for creating an object

// Create a User from a generated Elemental model.
user := models.NewUser() // always use the initializer to get various default value correctly set.
user.FullName := "Antoine Mercadal"
user.Login := "primalmotion"

// Create Mongo Manipulator.
m := manipmongo.NewMongoManipulator("127.0.0.1", "test")

// Then create the User.
m.Create(nil, user)

Example for retreving an object

// Create a Context with a filter.
ctx := manipulate.NewContextWithFilter(manipulate.NewFilterComposer().
    WithKey("login").
    Equals("primalmotion").
    Done(),
)

// Retrieve the users matching the filter.
var users models.UserLists
m.RetrieveMany(ctx, models.UserIdentity, &users)

Example to retrieve an Aporeto Processing Unit

Note: this is a specific Aporeto use case.

package main

import (
    "flag"
    "fmt"
    "os"

    "go.aporeto.io/gaia/squallmodels/v1/golang"
    "go.aporeto.io/manipulate"
    "go.aporeto.io/manipulate/manipwebsocket"
)

const aporetoAPIURL = "https://squall.console.aporeto.com"

func main() {

    // Here we get the cli parameters. Nothing exciting.
    var token, namespace string
    flag.StringVar(&token, "token", "", "A valid Aporeto token")
    flag.StringVar(&namespace, "namespace", "", "Your namespace")
    flag.Parse()
    if token == "" || namespace == "" {
        fmt.Println("Please pass both the -token and -namespace paramaters")
        os.Exit(1)
    }

    // We want to recursively retrieve all the running processing units starting
    // from the given namespace.

    // We first create a simple manipulator using an existing token. There are more
    // sophisticated ways of doing this, such as using
    // manipwebsocket.NewWebSocketManipulatorWithMidgardCertAuthentication to handle
    // automatic token renewal based on a certificate, but we'll keep this example simple.
    manipulator, disconnect, err := manipwebsocket.NewWebSocketManipulator(
        "Bearer",
        token,
        aporetoAPIURL,
        namespace,
    )
    if err != nil {
        panic(err)
    }

    // As we want only the Running processing unit, we need to filter them on
    // the operationalstatus status tag.
    // To do so, we need to create a manipulate.Context and give it a filter.
    mctx := manipulate.NewContextWithFilter(
        manipulate.NewFilterComposer().
            WithKey("operationalstatus").Equals("Running").
            Done(),
    )

    // Then as we want to get all processing units recursively, we set
    // the Recursive parameter of the context to true.
    mctx.Recursive = true

    // We create a ProcessingUnitsList to store the results.
    var pus squallmodels.ProcessingUnitsList

    // We call the manipulator.RetrieveMany using our context to retrieve the data.
    if err := manipulator.RetrieveMany(mctx, &pus); err != nil {
        panic(err)
    }

    // We print the results.
    for _, pu := range pus {
        fmt.Println("namespace:", pu.Namespace, "name:", pu.Name)
    }

    // And we nicely disconnect.
    disconnect()
}

Build this, retrieve a valid token (for instance using apoctl), then execute it:

./main -token $TOKEN -namespace /your-namespace

# Packages

Package maniphttp provides a ReST backed Manipulator.
No description provided by the author
Package manipmongo provides a MongoDB backed TransactionalManipulator.
Package maniptest contains a Mockable TransactionalManipulator.

# Functions

ContextOptionFields sets the list of fields to include in the reply.
ContextOptionFilter sets the filter.
ContextOptionFinalizer sets the create finalizer option of the context.
ContextOptionNamespace sets the namespace.
ContextOptionOrder sets the ordering option of the context.
ContextOptionOverride sets the override option of the context.
ContextOptionPage sets the pagination option of the context.
ContextOptionParameters sets the parameters option of the context.
ContextOptionParent sets the parent option of the context.
ContextOptionReadConsistency sets the desired read consistency of the request.
ContextOptionRecursive sets the recursive option of the context.
ContextOptionTracking sets the opentracing tracking option of the context.
ContextOptionTransationID sets the parameters option of the context.
ContextOptionVersion sets the version option of the context.
ContextOptionWriteConsistency sets the desired write consistency of the request.
IsCannotBuildQueryError returns true if the given error is am ErrCannotBuildQuery.
IsCannotCommitError returns true if the given error is am ErrCannotCommit.
IsCannotCommunicateError returns true if the given error is am ErrCannotCommunicate.
IsCannotExecuteQueryError returns true if the given error is am ErrCannotExecuteQuery.
IsCannotMarshalError returns true if the given error is am ErrCannotMarshal.
IsCannotUnmarshalError returns true if the given error is am ErrCannotUnmarshal.
IsConstraintViolationError returns true if the given error is am ErrConstraintViolation.
IsDisconnectedError returns true if the given error is am ErrDisconnected.
IsLockedError returns true if the given error is am ErrLocked.
IsMultipleObjectsFoundError returns true if the given error is am ErrMultipleObjectsFound.
IsNotImplementedError returns true if the given error is am ErrNotImplemented.
IsObjectNotFoundError returns true if the given error is am ErrObjectNotFound.
IsTooManyRequestsError returns true if the given error is am ErrTooManyRequests.
IsTransactionNotFoundError returns true if the given error is am ErrTransactionNotFound.
NewContext creates a context with the given ContextOption.
NewErrCannotBuildQuery returns a new ErrCannotBuildQuery.
NewErrCannotCommit returns a new ErrCannotCommit.
NewErrCannotCommunicate returns a new ErrCannotCommunicate.
NewErrCannotExecuteQuery returns a new ErrCannotExecuteQuery.
NewErrCannotMarshal returns a new ErrCannotMarshal.
NewErrCannotUnmarshal returns a new ErrCannotUnmarshal.
NewErrConstraintViolation returns a new ErrConstraintViolation.
NewErrDisconnected returns a new ErrDisconnected.
NewErrLocked returns a new ErrCannotCommunicate.
NewErrMultipleObjectsFound returns a new ErrMultipleObjectsFound.
NewErrNotImplemented returns a new ErrNotImplemented.
NewErrObjectNotFound returns a new ErrObjectNotFound.
NewErrTooManyRequests returns a new ErrCannotCommunicate.
NewErrTransactionNotFound returns a new ErrTransactionNotFound.
NewFilter returns a new filter.
NewFilterComposer returns a FilterComposer.
NewFilterFromString returns a new filter computed from the given string.
NewFilterParser returns an instance of FilterParser for the given input.
NewTransactionID returns a new transaction ID.
Retry will retry the given function that performs a manipulate operation if it fails and the error is a manipulate.ErrCannotCommunicate.

# Constants

Operators represent various operators.
Operators represent various operators.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Comparators represent various comparison operations.
Operators represent various operators.
Various values for Consistency.
Various values for Consistency.
Various values for Consistency.
Various values for Consistency.
Various values for Consistency.
Various values of SubscriberEvent.
Various values of SubscriberEvent.
Various values of SubscriberEvent.
Various values of SubscriberEvent.
Various values of SubscriberEvent.
Various values of SubscriberEvent.
Various values of SubscriberEvent.
Various values for Consistency.
Various values for Consistency.
Various values for Consistency.
Various values for Consistency.

# Structs

ErrCannotBuildQuery represents query building error.
ErrCannotCommit represents commit execution error.
ErrCannotCommunicate represents a failure in backend communication.
ErrCannotExecuteQuery represents query execution error.
ErrCannotMarshal represents marshaling error.
ErrCannotUnmarshal represents unmarshaling error.
ErrConstraintViolation represents a failure to find a transaction.
ErrDisconnected represents an error due user disconnection.
ErrLocked represents the error returned when the server api is locked..
ErrMultipleObjectsFound represents too many object found error.
ErrNotImplemented represents a non implemented function.
ErrObjectNotFound represents object not found error.
ErrTooManyRequests represents the error returned when the server api is locked..
ErrTransactionNotFound represents a failure to find a transaction.
Filter is a filter struct which can be used with Cassandra.
FilterParser represents a Parser.

# Interfaces

A Context holds all information regarding a particular manipulate operation.
FilterKeyComposer composes a filter.
FilterValueComposer adds values and operators.
Manipulator is the interface of a storage backend.
A Subscriber is the interface to control a push event subscription.
A TokenManager issues an renew tokens periodically.
A TransactionalManipulator is a Manipulator that handles transactions.

# Type aliases

ContextOption represents an option can can be passed to NewContext.
An FilterComparator is the type of a operator used by a filter.
FilterComparators are a list of FilterOperator.
FilterKeys represents a list of FilterKey.
An FilterOperator is the type of a operator used by a filter.
FilterOperators are a list of FilterOperator.
FilterValue represents a filter value.
FilterValues represents a list of FilterValue.
A FinalizerFunc is the type of a function that can be used as a creation finalizer.
ReadConsistency represents the desired consistency of the request.
SubFilter is the type of subfilter.
SubFilters is is a list SubFilter,.
SubscriberStatus is the type of a subscriber status.
TransactionID is the type used to define a transcation ID of a store.
WriteConsistency represents the desired consistency of the request.