Documentation ¶
Index ¶
- Constants
- func GetDataType(entity Entity) string
- func IsUniqueViolation(err error) bool
- type BackendConfig
- type BaseEntity
- func (e *BaseEntity) GetCreateTime() time.Time
- func (e *BaseEntity) GetDelete() bool
- func (e *BaseEntity) GetID() string
- func (e *BaseEntity) GetModifiedTime() time.Time
- func (e *BaseEntity) GetName() string
- func (e *BaseEntity) GetOrganizationID() string
- func (e *BaseEntity) GetReason() Reason
- func (e *BaseEntity) GetRevision() uint64
- func (e *BaseEntity) GetSpec() Spec
- func (e *BaseEntity) GetStatus() Status
- func (e *BaseEntity) GetTags() Tags
- func (e *BaseEntity) GetVersion() uint64
- func (e *BaseEntity) SetDelete(delete bool)
- func (e *BaseEntity) SetReason(reason Reason)
- func (e *BaseEntity) SetSpec(spec Spec)
- func (e *BaseEntity) SetStatus(status Status)
- func (e *BaseEntity) SetTags(tags Tags)
- type DataType
- type Entity
- type EntityStore
- type Filter
- type FilterStat
- type Options
- type Reason
- type Scope
- type Spec
- type Status
- type Tags
- type Verb
Constants ¶
const ( // FilterVerbIn tests containment FilterVerbIn Verb = "in" // FilterVerbEqual tests equality FilterVerbEqual Verb = "equal" // FilterVerbBefore tests two time.Time FilterVerbBefore Verb = "before" // FilterVerbAfter tests two time.Time FilterVerbAfter Verb = "after" // FilterScopeField defines that the subject is a BaseEntity field FilterScopeField Scope = "field" // FilterScopeTag defines that the subject is a BaseEntity Tag FilterScopeTag Scope = "tag" // FilterScopeExtra defines that the subject is a extra field extended from BaseEntity FilterScopeExtra Scope = "extra" )
Variables ¶
This section is empty.
Functions ¶
func GetDataType ¶
GetDataType returns the data type of the given entity
func IsUniqueViolation ¶ added in v0.1.13
IsUniqueViolation is a helper function to safely return UniqueViolation if available
Types ¶
type BackendConfig ¶ added in v0.1.13
type BackendConfig struct { Backend string Address string Username string Password string Bucket string }
BackendConfig list a set of configuration values for backend DB
type BaseEntity ¶
type BaseEntity struct { ID string `json:"id"` Name string `json:"name"` OrganizationID string `json:"organizationId"` CreatedTime time.Time `json:"createdTime,omitempty"` ModifiedTime time.Time `json:"modifiedTime,omitempty"` Revision uint64 `json:"revision"` Version uint64 `json:"version"` Spec Spec `json:"state"` Status Status `json:"status"` Reason Reason `json:"reason"` Tags Tags `json:"tags"` Delete bool `json:"delete"` Context context.Context `json:"-"` }
BaseEntity is the base struct for all stored objects
func (*BaseEntity) GetCreateTime ¶ added in v0.1.13
func (e *BaseEntity) GetCreateTime() time.Time
GetCreateTime gets the entity creation time
func (*BaseEntity) GetDelete ¶ added in v0.1.13
func (e *BaseEntity) GetDelete() bool
GetDelete gets the entity delete status
func (*BaseEntity) GetID ¶ added in v0.1.13
func (e *BaseEntity) GetID() string
GetID gets the entity ID
func (*BaseEntity) GetModifiedTime ¶
func (e *BaseEntity) GetModifiedTime() time.Time
GetModifiedTime gets the entity modification time
func (*BaseEntity) GetName ¶
func (e *BaseEntity) GetName() string
GetName retreives the entity name
func (*BaseEntity) GetOrganizationID ¶ added in v0.1.13
func (e *BaseEntity) GetOrganizationID() string
GetOrganizationID gets the entity organizationID
func (*BaseEntity) GetReason ¶ added in v0.1.13
func (e *BaseEntity) GetReason() Reason
GetReason gets the entity reason
func (*BaseEntity) GetRevision ¶
func (e *BaseEntity) GetRevision() uint64
GetRevision gets the entity revision
func (*BaseEntity) GetSpec ¶ added in v0.1.13
func (e *BaseEntity) GetSpec() Spec
GetSpec gets the entity spec
func (*BaseEntity) GetStatus ¶
func (e *BaseEntity) GetStatus() Status
GetStatus gets the entity status
func (*BaseEntity) GetVersion ¶ added in v0.1.13
func (e *BaseEntity) GetVersion() uint64
GetVersion gets the entity version
func (*BaseEntity) SetDelete ¶ added in v0.1.13
func (e *BaseEntity) SetDelete(delete bool)
SetDelete sets the entity delete status
func (*BaseEntity) SetReason ¶ added in v0.1.13
func (e *BaseEntity) SetReason(reason Reason)
SetReason sets the entity reason
func (*BaseEntity) SetSpec ¶ added in v0.1.13
func (e *BaseEntity) SetSpec(spec Spec)
SetSpec sets the entity spec
func (*BaseEntity) SetStatus ¶ added in v0.1.13
func (e *BaseEntity) SetStatus(status Status)
SetStatus sets the entity status
func (*BaseEntity) SetTags ¶ added in v0.1.13
func (e *BaseEntity) SetTags(tags Tags)
SetTags sets the entity tags
type Entity ¶
type Entity interface { SetSpec(Spec) SetStatus(Status) SetReason(Reason) SetTags(Tags) SetDelete(bool) GetID() string GetName() string GetOrganizationID() string GetCreateTime() time.Time GetModifiedTime() time.Time GetRevision() uint64 GetVersion() uint64 GetSpec() Spec GetStatus() Status GetReason() Reason GetTags() Tags GetDelete() bool // contains filtered or unexported methods }
Entity is the base interface for all stored objects
type EntityStore ¶
type EntityStore interface { // Add adds new entities to the store Add(ctx context.Context, entity Entity) (id string, err error) // Update updates existing entities to the store Update(ctx context.Context, lastRevision uint64, entity Entity) (revision int64, err error) // GetById gets a single entity by key from the store Get(ctx context.Context, organizationID string, key string, opts Options, entity Entity) error // Find is like get, but returns a bool to indicate whether the entity exists (or was "found") Find(ctx context.Context, organizationID string, key string, opts Options, entity Entity) (bool, error) // List fetches a list of entities of a single data type satisfying the filter. // entities is a placeholder for results and must be a pointer to an empty slice of the desired entity type. List(ctx context.Context, organizationID string, opts Options, entities interface{}) error // ListGlobal fetches a list of entities of a single data type satisfying the filter across all orgs. // entities is a placeholder for results and must be a pointer to an empty slice of the desired entity type. ListGlobal(ctx context.Context, opts Options, entities interface{}) error // Delete deletes a single entity from the store. Delete(ctx context.Context, organizationID string, id string, entity Entity) error // SoftDelete sets the deleted flag and status, but does not actually delete the entity from the store. SoftDelete(ctx context.Context, entity Entity) error // UpdateWithError is used by entity handlers to save changes and/or error status // e.g. `defer func() { h.store.UpdateWithError(e, err) }()` UpdateWithError(ctx context.Context, e Entity, err error) }
EntityStore is a wrapper around libkv and provides convenience methods to serializing and deserializing objects
func NewFromBackend ¶ added in v0.1.13
func NewFromBackend(config BackendConfig) (EntityStore, error)
NewFromBackend creates new entity store created from a backend DB
type Filter ¶
type Filter interface { Add(...FilterStat) Filter FilterStats() []FilterStat }
Filter defines a set of criteria to filter entities when listing
func FilterByApplication ¶ added in v0.1.13
FilterByApplication creates a filter, which will filter based on the supplied application name
func FilterEverything ¶ added in v0.1.13
func FilterEverything() Filter
FilterEverything creates a filter, which will matches all entities
func FilterExists ¶ added in v0.1.13
func FilterExists() Filter
FilterExists creates a filter, which will filter entities with Delete=true
type FilterStat ¶ added in v0.1.13
FilterStat (Filter Statement) defines one filter criterion
func FilterStatByApplication ¶ added in v0.1.13
func FilterStatByApplication(name string) FilterStat
FilterStatByApplication defines one filter statement by application name
type Options ¶ added in v0.1.13
type Options struct {
Filter Filter
}
Options defines a set of query options for list and get
type Reason ¶ added in v0.1.13
type Reason []string
Reason represents the reason of current status
type Scope ¶ added in v0.1.13
type Scope string
Scope describes which scope this filter is applied on
type Spec ¶
Spec represents the desired state/status
type Status ¶
type Status string
Status represents the current state
const ( // StatusINITIALIZED object is INITIALIZED // this status is used by image manager StatusINITIALIZED Status = "INITIALIZED" // StatusCREATING object is CREATING // it is not a guarantee that the object is also created and ready in the underlying driver // should wait until the READY state to use the object StatusCREATING Status = "CREATING" // StatusREADY object is READY to be used StatusREADY Status = "READY" // StatusUPDATING object is UPDATING // it is not a guarantee that changes will be reflected by the underlying driver // when updated, will transfer to READY state StatusUPDATING Status = "UPDATING" // StatusDELETING object is DELETING // it is not a guarantee that it has been deleted from the underlying driver // user should not reuse the object name until it is transfered to DELETED state StatusDELETING Status = "DELETING" // StatusDELETED object is DELETED // Note for dispatch team: // leave this here, reserved for when we use UUID instead of entity name StatusDELETED Status = "DELETED" // StatusERROR unexpected error state // you should not use the object until the state is tranfered to READY // or the object is deleted StatusERROR Status = "ERROR" // StatusMISSING temporary error state // Used when external resources cannot be found StatusMISSING Status = "MISSING" // StatusUNKNOWN is not an error, just that the current status is inderminate StatusUNKNOWN Status = "UNKNOWN" )