Documentation ¶
Overview ¶
Package bambou provides the basic contructs used by ReST frameworks generated using Monolithe.
Bambou provides a set of objects that allow the manipulation of ReST entities very easily. It deals with all possible CRUD operations and defines all these low level operations in a single place.
Index ¶
- Variables
- func Logger() *logging.Logger
- type Error
- type Event
- type EventHandler
- type EventsList
- type FetchingInfo
- type Identifiable
- type IdentifiablesList
- type Identity
- type Notification
- type NotificationsChannel
- type PushCenter
- type Rootable
- type Session
- func (s *Session) AssignChildren(parent Identifiable, children []Identifiable, identity Identity) *Error
- func (s *Session) CreateChild(parent Identifiable, child Identifiable) *Error
- func (s *Session) DeleteEntity(object Identifiable) *Error
- func (s *Session) FetchChildren(parent Identifiable, identity Identity, dest interface{}, info *FetchingInfo) *Error
- func (s *Session) FetchEntity(object Identifiable) *Error
- func (s *Session) NextEvent(channel NotificationsChannel, lastEventID string) *Error
- func (s *Session) Reset()
- func (s *Session) Root() Rootable
- func (s *Session) SaveEntity(object Identifiable) *Error
- func (s *Session) SetInsecureSkipVerify(skip bool) *Error
- func (s *Session) Start() *Error
- type Storer
- type VsdError
- type VsdErrorList
Constants ¶
This section is empty.
Variables ¶
var AllIdentity = Identity{
Name: "__all__",
Category: "__all__",
}
AllIdentity represents all possible Identities.
Functions ¶
Types ¶
type Error ¶
func NewBambouError ¶
type Event ¶
type Event struct { DataMap []map[string]interface{} `json:"entities"` Data []byte `json:"-"` EntityType string `json:"entityType"` Type string `json:"type"` UpdateMechanism string `json:"updateMechanism"` }
Event represents one item of a Notification. It will contain data from the server regarding the object that has been created, deleted, or modified.
type EventHandler ¶
type EventHandler func(*Event)
EventHandler is prototype of a Push Center Handler.
type FetchingInfo ¶
type FetchingInfo struct { Filter string FilterType string GroupBy []string OrderBy string Page int PageSize int TotalCount int }
FetchingInfo is a structure that contains differents values about the fetching of children, either for the user to set, of for the server to fill. This structure will be used to pass and get back information during the fetching of some children.
func NewFetchingInfo ¶
func NewFetchingInfo() *FetchingInfo
NewFetchingInfo returns a new *FetchingInfo
func (*FetchingInfo) String ¶
func (f *FetchingInfo) String() string
String returns the string representation of the FetchingInfo.
type Identifiable ¶
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) }
Identifiable is the interface that object which have Identity must implement.
type IdentifiablesList ¶
type IdentifiablesList []Identifiable
IdentifiablesList is a list of objects implementing the Identifiable interface.
type Identity ¶
Identity is a structure that contains the necessary information about an Identifiable. The Name is usually the singular form of the Category. For instance, "enterprise" and "enterprises".
type Notification ¶
type Notification struct { Events EventsList `json:"events"` UUID string `json:"uuid"` }
Notification represents a collection of Event structures. It also contains a identifier for the Notification.
func NewNotification ¶
func NewNotification() *Notification
NewNotification returns a new *Notification.
type NotificationsChannel ¶
type NotificationsChannel chan *Notification
NotificationsChannel is used to received notification from the session
type PushCenter ¶
type PushCenter struct { Channel NotificationsChannel // contains filtered or unexported fields }
PushCenter is a structure that allows the user to deal with notifications. You can register multiple handlers for several Identity. When a notification is sent by the server and the Identity of its content matches one of the registered handler, this handler will be called.
func NewPushCenter ¶
func NewPushCenter(session *Session) *PushCenter
NewPushCenter creates a new PushCenter.
func (*PushCenter) HasHandlerForIdentity ¶
func (p *PushCenter) HasHandlerForIdentity(identity Identity) bool
HasHandlerForIdentity verifies if the given identity has a registered handler.
func (*PushCenter) RegisterHandlerForIdentity ¶
func (p *PushCenter) RegisterHandlerForIdentity(handler EventHandler, identity Identity)
RegisterHandlerForIdentity registers the given EventHandler for the given Entity Identity. You can pass the bambou.AllIdentity as identity to register the handler for all events. If you pass a handler for an Identity that is already registered the previous handler will be silently overwriten.
func (*PushCenter) UnregisterHandlerForIdentity ¶
func (p *PushCenter) UnregisterHandlerForIdentity(identity Identity)
UnregisterHandlerForIdentity unegisters the given EventHandler for the given Entity Identity.
type Rootable ¶
type Rootable interface { Identifiable // APIKey returns the token that will be used to authentify the communication // between a Storer and the backend. APIKey() string // SetAPIKey sets the token used by the Storer. SetAPIKey(string) }
Rootable is the interface that must be implemented by the root object of the API. A Rootable also implements the Identifiable interface.
type Session ¶
type Session struct { Certificate *tls.Certificate Username string Password string Organization string URL string // contains filtered or unexported fields }
Session represents a user session. It provides the entire communication layer with the backend. It must implement the Operationable interface. A session can be authenticated via 1) TLS certificates or 2) user + password (different API endpoints)
func NewSession ¶
NewSession returns a new *Session You need to provide a Rootable object that will be used to contain the results of the authentication process, like the api key for instance. Authentication using user + password
func NewX509Session ¶
func NewX509Session(cert *tls.Certificate, url string, root Rootable) *Session
func (*Session) AssignChildren ¶
func (s *Session) AssignChildren(parent Identifiable, children []Identifiable, identity Identity) *Error
AssignChildren assigns the list of given child Identifiables to the given Identifiable parent in the server.
func (*Session) CreateChild ¶
func (s *Session) CreateChild(parent Identifiable, child Identifiable) *Error
CreateChild creates a new child Identifiable under the given parent Identifiable in the server.
func (*Session) DeleteEntity ¶
func (s *Session) DeleteEntity(object Identifiable) *Error
DeleteEntity deletes the given Identifiable from the server.
func (*Session) FetchChildren ¶
func (s *Session) FetchChildren(parent Identifiable, identity Identity, dest interface{}, info *FetchingInfo) *Error
FetchChildren fetches the children with of given parent identified by the given Identity.
func (*Session) FetchEntity ¶
func (s *Session) FetchEntity(object Identifiable) *Error
FetchEntity fetchs the given Identifiable from the server.
func (*Session) NextEvent ¶
func (s *Session) NextEvent(channel NotificationsChannel, lastEventID string) *Error
NextEvent will return the next notification from the backend as it occurs and will send it to the correct channel.
func (*Session) SaveEntity ¶
func (s *Session) SaveEntity(object Identifiable) *Error
SaveEntity saves the given Identifiable into the server.
func (*Session) SetInsecureSkipVerify ¶
Dummy function avail for backwards compat. Logic moved to the new session methods
type Storer ¶
type Storer interface { Start() *Error Reset() Root() Rootable FetchEntity(Identifiable) *Error SaveEntity(Identifiable) *Error DeleteEntity(Identifiable) *Error FetchChildren(Identifiable, Identity, interface{}, *FetchingInfo) *Error CreateChild(Identifiable, Identifiable) *Error AssignChildren(Identifiable, []Identifiable, Identity) *Error NextEvent(NotificationsChannel, string) *Error }
Storer is the interface that must be implemented by object that can perform CRUD operations on RemoteObjects.
func CurrentSession ¶
func CurrentSession() Storer
CurrentSession returns the current active and authenticated Session.