node

package
v0.0.0-...-e2755d2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Prefix for all node keys in the registry
	Prefix = "nodes/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Core

type Core struct {
	// contains filtered or unexported fields
}

Core implements all business logic for node

func (*Core) AcquireNode

func (c *Core) AcquireNode(ctx context.Context, m *Model, sessionID string) error

AcquireNode to create a node model with acquiring a lock on it

func (*Core) CreateNode

func (c *Core) CreateNode(ctx context.Context, m *Model) error

CreateNode creates a new node

func (*Core) DeleteNode

func (c *Core) DeleteNode(ctx context.Context, m *Model) error

DeleteNode deletes a node and all resources in it

func (*Core) Exists

func (c *Core) Exists(ctx context.Context, key string) (bool, error)

Exists to check if the node exists with fully qualified consul key

func (*Core) ExistsWithID

func (c *Core) ExistsWithID(ctx context.Context, id string) (bool, error)

ExistsWithID to check if the node exists with the ID

func (*Core) List

func (c *Core) List(ctx context.Context, prefix string) ([]*Model, error)

List gets slice of nodes starting with given prefix

func (*Core) ListKeys

func (c *Core) ListKeys(ctx context.Context, prefix string) ([]string, error)

ListKeys gets all node keys

type ICore

type ICore interface {
	CreateNode(ctx context.Context, m *Model) error
	Exists(ctx context.Context, key string) (bool, error)
	AcquireNode(ctx context.Context, m *Model, sessionID string) error
	ExistsWithID(ctx context.Context, id string) (bool, error)
	DeleteNode(ctx context.Context, m *Model) error
	ListKeys(ctx context.Context, prefix string) ([]string, error)
	List(ctx context.Context, prefix string) ([]*Model, error)
}

ICore is an interface over node core

func NewCore

func NewCore(repo IRepo) ICore

NewCore returns an instance of Core

type IRepo

type IRepo interface {
	common.IRepo
	List(ctx context.Context, prefix string) ([]common.IModel, error)
}

IRepo interface over database repository

func NewRepo

func NewRepo(registry registry.IRegistry) IRepo

NewRepo returns IRepo

type Model

type Model struct {
	common.BaseModel
	ID string `json:"id"`
}

Model for a node

func (*Model) Key

func (m *Model) Key() string

Key returns the key for storing in the registry

func (*Model) Prefix

func (m *Model) Prefix() string

Prefix returns the key prefix

type Repo

type Repo struct {
	common.BaseRepo
}

Repo implements various repository methods

func (*Repo) List

func (r *Repo) List(ctx context.Context, prefix string) ([]common.IModel, error)

List returns a slice of Nodes matching prefix

Jump to

Keyboard shortcuts

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