utils

package
v0.0.0-...-cef23b5 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateNodeID

func GenerateNodeID() (string, error)

func IsMySelf

func IsMySelf(peerID string, wfa Accessor) (bool, string)

func NotifyChange

func NotifyChange(dt tools.DataType, id string, obj ShallowDBObject, deleted bool)

NotifyChange broadcasts a ChangeEvent to all current subscribers for dt. Non-blocking: events are dropped for subscribers whose buffer is full.

func SubscribeChanges

func SubscribeChanges(dt tools.DataType) (<-chan ChangeEvent, func())

SubscribeChanges returns a channel that receives ChangeEvents for dt whenever an object of that type is written or deleted in this process. Call the returned cancel function to unsubscribe; after that the channel will no longer receive events (it is not closed — use a context to stop reading).

func VerifyAccess

func VerifyAccess(a Accessor, id string) error

Types

type AbstractAccessor

type AbstractAccessor[T DBObject] struct {
	Logger                zerolog.Logger    // Logger is the logger of the accessor, it's a specilized logger for the accessor
	Type                  tools.DataType    // Type is the data type of the accessor
	Request               *tools.APIRequest // Caller is the http caller of the accessor (optionnal) only need in a peer connection
	ResourceModelAccessor Accessor
	New                   func() T
	NotImplemented        []string
}

func (*AbstractAccessor[T]) CopyOne

func (a *AbstractAccessor[T]) CopyOne(data DBObject) (DBObject, int, error)

func (*AbstractAccessor[T]) DeleteOne

func (a *AbstractAccessor[T]) DeleteOne(id string) (DBObject, int, error)

* Nothing special here, just the basic CRUD operations

func (*AbstractAccessor[T]) GetCaller

func (dma *AbstractAccessor[T]) GetCaller() *tools.HTTPCaller

func (*AbstractAccessor[T]) GetExec

func (a *AbstractAccessor[T]) GetExec(isDraft bool) func(DBObject) ShallowDBObject

func (*AbstractAccessor[T]) GetGroups

func (dma *AbstractAccessor[T]) GetGroups() []string

func (*AbstractAccessor[T]) GetLogger

func (dma *AbstractAccessor[T]) GetLogger() *zerolog.Logger

func (*AbstractAccessor[T]) GetPeerID

func (dma *AbstractAccessor[T]) GetPeerID() string

func (*AbstractAccessor[T]) GetRequest

func (r *AbstractAccessor[T]) GetRequest() *tools.APIRequest

func (*AbstractAccessor[T]) GetType

func (dma *AbstractAccessor[T]) GetType() tools.DataType

func (*AbstractAccessor[T]) GetUser

func (dma *AbstractAccessor[T]) GetUser() string

func (*AbstractAccessor[T]) LoadAll

func (a *AbstractAccessor[T]) LoadAll(isDraft bool, offset int64, limit int64) ([]ShallowDBObject, int, error)

func (*AbstractAccessor[T]) LoadOne

func (a *AbstractAccessor[T]) LoadOne(id string) (DBObject, int, error)

func (*AbstractAccessor[T]) NewObj

func (r *AbstractAccessor[T]) NewObj() DBObject

func (*AbstractAccessor[T]) Search

func (a *AbstractAccessor[T]) Search(filters *dbs.Filters, search string, isDraft bool, offset int64, limit int64) ([]ShallowDBObject, int, error)

func (*AbstractAccessor[T]) ShouldVerifyAuth

func (r *AbstractAccessor[T]) ShouldVerifyAuth() bool

func (*AbstractAccessor[T]) StoreOne

func (a *AbstractAccessor[T]) StoreOne(data DBObject) (DBObject, int, error)

func (*AbstractAccessor[T]) UpdateOne

func (a *AbstractAccessor[T]) UpdateOne(set map[string]interface{}, id string) (DBObject, int, error)

type AbstractObject

type AbstractObject struct {
	UUID          string     `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
	NotInCatalog  bool       `json:"not_in_catalog" bson:"not_in_catalog" default:"false"`
	Name          string     `json:"name,omitempty" bson:"name,omitempty" validate:"required"`
	IsDraft       bool       `json:"is_draft" bson:"is_draft" default:"false"`
	CreatorID     string     `json:"creator_id,omitempty" bson:"creator_id,omitempty"`
	UserCreatorID string     `json:"user_creator_id,omitempty" bson:"user_creator_id,omitempty"`
	CreationDate  time.Time  `json:"creation_date,omitempty" bson:"creation_date,omitempty"`
	UpdateDate    time.Time  `json:"update_date,omitempty" bson:"update_date,omitempty"`
	UpdaterID     string     `json:"updater_id,omitempty" bson:"updater_id,omitempty"`
	UserUpdaterID string     `json:"user_updater_id,omitempty" bson:"user_updater_id,omitempty"`
	AccessMode    AccessMode `json:"access_mode" bson:"access_mode" default:"0"`
	Signature     []byte     `bson:"signature,omitempty" json:"signature,omitempty"`
}

* AbstractObject is a struct that represents the basic fields of an object * it defines the object id and name * every data in base root model should inherit from this struct (only exception is the ResourceModel)

func (*AbstractObject) CanDelete

func (r *AbstractObject) CanDelete() bool

func (*AbstractObject) CanUpdate

func (r *AbstractObject) CanUpdate(set DBObject) (bool, DBObject)

func (*AbstractObject) DeepCopy

func (r *AbstractObject) DeepCopy() *AbstractObject

func (*AbstractObject) Deserialize

func (dma *AbstractObject) Deserialize(j map[string]interface{}, obj DBObject) DBObject

func (*AbstractObject) Extend

func (ri *AbstractObject) Extend(typ ...string) map[string][]tools.DataType

func (*AbstractObject) GenerateID

func (r *AbstractObject) GenerateID()

func (*AbstractObject) GetAccessor

func (ri *AbstractObject) GetAccessor(request *tools.APIRequest) Accessor

func (*AbstractObject) GetCreatorID

func (ao *AbstractObject) GetCreatorID() string

func (AbstractObject) GetID

func (ao AbstractObject) GetID() string

GetID implements ShallowDBObject.

func (AbstractObject) GetName

func (ao AbstractObject) GetName() string

GetName implements ShallowDBObject.

func (*AbstractObject) GetObjectFilters

func (ao *AbstractObject) GetObjectFilters(search string) *dbs.Filters

func (AbstractObject) GetSignature

func (ao AbstractObject) GetSignature() []byte

func (*AbstractObject) IsDrafted

func (r *AbstractObject) IsDrafted() bool

func (*AbstractObject) IsNotInCatalog

func (r *AbstractObject) IsNotInCatalog() bool

func (*AbstractObject) Serialize

func (dma *AbstractObject) Serialize(obj DBObject) map[string]interface{}

func (*AbstractObject) SetID

func (r *AbstractObject) SetID(id string)

func (*AbstractObject) SetName

func (r *AbstractObject) SetName(name string)

func (*AbstractObject) SetNotInCatalog

func (r *AbstractObject) SetNotInCatalog(ok bool)

func (*AbstractObject) Sign

func (r *AbstractObject) Sign()

func (*AbstractObject) StoreDraftDefault

func (r *AbstractObject) StoreDraftDefault()

func (*AbstractObject) Unsign

func (r *AbstractObject) Unsign()

func (*AbstractObject) UpToDate

func (ao *AbstractObject) UpToDate(user string, peer string, create bool)

func (*AbstractObject) VerifyAuth

func (ao *AbstractObject) VerifyAuth(callName string, request *tools.APIRequest) bool

type AccessMode

type AccessMode int
const (
	Private AccessMode = iota
	Public
)

type Accessor

type Accessor interface {
	NewObj() DBObject
	GetUser() string
	GetPeerID() string
	GetGroups() []string
	ShouldVerifyAuth() bool
	GetType() tools.DataType
	GetLogger() *zerolog.Logger
	GetCaller() *tools.HTTPCaller
	GetRequest() *tools.APIRequest
	LoadOne(id string) (DBObject, int, error)
	DeleteOne(id string) (DBObject, int, error)
	CopyOne(data DBObject) (DBObject, int, error)
	StoreOne(data DBObject) (DBObject, int, error)
	LoadAll(isDraft bool, offset int64, limit int64) ([]ShallowDBObject, int, error)
	UpdateOne(set map[string]interface{}, id string) (DBObject, int, error)
	Search(filters *dbs.Filters, search string, isDraft bool, offset int64, limit int64) ([]ShallowDBObject, int, error)
	GetExec(isDraft bool) func(DBObject) ShallowDBObject
}

Accessor is an interface that defines the basic methods for an Accessor

type ChangeEvent

type ChangeEvent struct {
	DataType tools.DataType
	ID       string
	Object   ShallowDBObject // nil only when the load after the write failed
	Deleted  bool
}

ChangeEvent is fired whenever a DB object is created, updated or deleted within this process. Deleted=true means the object was removed; Object is the last known snapshot before deletion.

type DBObject

type DBObject interface {
	GenerateID()
	Extend(typ ...string) map[string][]tools.DataType
	SetNotInCatalog(bool)
	IsNotInCatalog() bool
	SetID(id string)
	GetID() string
	GetName() string
	SetName(name string)
	IsDrafted() bool
	CanDelete() bool
	StoreDraftDefault()
	GetCreatorID() string
	UpToDate(user string, peer string, create bool)
	CanUpdate(set DBObject) (bool, DBObject)
	VerifyAuth(callName string, request *tools.APIRequest) bool
	Serialize(obj DBObject) map[string]interface{}
	GetAccessor(request *tools.APIRequest) Accessor
	Deserialize(j map[string]interface{}, obj DBObject) DBObject
	Sign()
	Unsign()
	GetSignature() []byte
	GetObjectFilters(search string) *dbs.Filters
}

DBObject is an interface that defines the basic methods for a DBObject

func GenericDelete

func GenericDelete(res DBObject, a Accessor) (DBObject, int, error)

func GenericDeleteOne

func GenericDeleteOne(id string, a Accessor) (DBObject, int, error)

GenericLoadOne loads one object from the database (generic)

func GenericLoadOne

func GenericLoadOne[T DBObject](id string, data T, f func(DBObject) (DBObject, int, error), a Accessor) (DBObject, int, error)

func GenericRawUpdateOne

func GenericRawUpdateOne(set DBObject, id string, a Accessor) (DBObject, int, error)

GenericLoadOne loads one object from the database (generic) json expected in entry is a flatted object no need to respect the inheritance hierarchy

func GenericStoreOne

func GenericStoreOne(data DBObject, a Accessor) (DBObject, int, error)

GenericLoadOne loads one object from the database (generic)

func GenericUpdateOne

func GenericUpdateOne(change map[string]interface{}, id string, a Accessor) (DBObject, int, error)

GenericLoadOne loads one object from the database (generic) json expected in entry is a flatted object no need to respect the inheritance hierarchy

func ModelGenericUpdateOne

func ModelGenericUpdateOne(change map[string]interface{}, id string, a Accessor) (DBObject, map[string]interface{}, int, error)

type Owner

type Owner struct {
	Name string `json:"name,omitempty" bson:"name,omitempty"`
}

type ShallowDBObject

type ShallowDBObject interface {
	DBObject
	GenerateID()
	GetID() string
	GetName() string
	Serialize(obj DBObject) map[string]interface{}
	Deserialize(j map[string]interface{}, obj DBObject) DBObject
}

ShallowDBObject is an interface that defines the basic methods shallowed version of a DBObject

func GenericLoadAll

func GenericLoadAll[T DBObject](f func(DBObject) ShallowDBObject, onlyDraft bool, wfa Accessor, opts ...int64) ([]ShallowDBObject, int, error)

func GenericSearch

func GenericSearch[T DBObject](filters *dbs.Filters, search string, defaultFilters *dbs.Filters,
	f func(DBObject) ShallowDBObject, onlyDraft bool, wfa Accessor, opts ...int64) ([]ShallowDBObject, int, error)

func GetMySelf

func GetMySelf(wfa Accessor) (ShallowDBObject, error)

Jump to

Keyboard shortcuts

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