object

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: GPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCache

func ClearCache()

ClearCache clears the global object cache store. Note, this is only used for unit tests not to run into "can't cache already cached object" error.

func DeleteFromCache

func DeleteFromCache(id types.Binary)

DeleteFromCache deletes the Object from the global cache store matching the given ID (if any).

func ID

func ID(source int64, tags map[string]string) types.Binary

TODO: the return value of this function must be stable like forever

func RestoreMutedObjects

func RestoreMutedObjects(ctx context.Context, db *database.DB) error

RestoreMutedObjects restores all muted objects and their extra / ID tags from the database. Note, this function only retrieves muted objects without non-recovered incident.

Returns an error on any database failure and panics when trying to cache an object that's already in the cache store.

func RestoreObjects

func RestoreObjects(ctx context.Context, db *database.DB, ids []types.Binary) error

RestoreObjects restores all objects and their (extra)tags matching the given IDs from the database. Returns error on any database failures and panics when trying to cache an object that's already in the cache store.

Types

type ExtraTagRow

type ExtraTagRow TagRow

ExtraTagRow represents a single database object extra tag like `hostgroup/foo: null`.

func (*ExtraTagRow) TableName

func (e *ExtraTagRow) TableName() string

TableName implements the contracts.TableNamer interface.

type IdTagRow

type IdTagRow TagRow

IdTagRow represents a single database object id tag.

func (*IdTagRow) TableName

func (e *IdTagRow) TableName() string

TableName implements the contracts.TableNamer interface.

type Object

type Object struct {
	ID         types.Binary `db:"id"`
	SourceID   int64        `db:"source_id"`
	Name       string       `db:"name"`
	URL        types.String `db:"url"`
	MuteReason types.String `db:"mute_reason"`

	Tags      map[string]string `db:"-"`
	ExtraTags map[string]string `db:"-"`
	// contains filtered or unexported fields
}

func FromEvent

func FromEvent(ctx context.Context, db *database.DB, ev *event.Event) (*Object, error)

FromEvent creates an object from the provided event tags if it's not in the cache and syncs all object related types with the database. Returns error on any database failure

func GetFromCache

func GetFromCache(id types.Binary) *Object

GetFromCache fetches an object from the global object cache store matching the given ID. Returns nil if it's not in the cache.

func New

func New(db *database.DB, ev *event.Event) *Object

New creates a new object from the given event.

func (*Object) DisplayName

func (o *Object) DisplayName() string

func (*Object) EvalEqual

func (o *Object) EvalEqual(key string, value string) (bool, error)

func (*Object) EvalExists

func (o *Object) EvalExists(key string) bool

func (*Object) EvalLess

func (o *Object) EvalLess(key string, value string) (bool, error)

func (*Object) EvalLessOrEqual

func (o *Object) EvalLessOrEqual(key string, value string) (bool, error)

func (*Object) EvalLike

func (o *Object) EvalLike(key string, value string) (bool, error)

EvalLike returns true when the objects tag/value matches the filter.Conditional value.

func (*Object) IsMuted

func (o *Object) IsMuted() bool

IsMuted returns whether the current object is muted by its source.

func (*Object) String

func (o *Object) String() string

func (*Object) Upsert

func (o *Object) Upsert() interface{}

Upsert implements the contracts.Upserter interface.

type TagRow

type TagRow struct {
	ObjectId types.Binary `db:"object_id"`
	Tag      string       `db:"tag"`
	Value    string       `db:"value"`
}

TagRow is a base type for IdTagRow and ExtraTagRow

Jump to

Keyboard shortcuts

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