kv

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const TemplatePrefix = "mg_templates:"
View Source
const WorkflowPrefix = "mg_workflows:"

Variables

This section is empty.

Functions

func CreateTemplateSafe

func CreateTemplateSafe(template TemplateItem) error

CreateTemplateSafe creates a template safely through the DB service

func CreateWorkflowSafe

func CreateWorkflowSafe(id string, workflow Workflow) error

CreateWorkflowSafe creates a workflow safely through the DB service

func DeleteTemplateSafe

func DeleteTemplateSafe(slug string) error

DeleteTemplateSafe deletes a template safely through the DB service

func DeleteValue

func DeleteValue(key string) error

DeleteValue is a convenience function for deleting a value using the global DB service

func DeleteWorkflowSafe

func DeleteWorkflowSafe(id string) error

DeleteWorkflowSafe deletes a workflow safely through the DB service

func GetValue

func GetValue(key string, value interface{}) error

GetValue is a convenience function for getting a value using the global DB service

func InitDB

func InitDB(appName string) (*badger.DB, error)

func ListValues

func ListValues(prefix string) ([]string, error)

ListValues is a convenience function for listing values using the global DB service

func SetValue

func SetValue(key string, value interface{}) error

SetValue is a convenience function for setting a value using the global DB service

Types

type Atom

type Atom struct {
	Command     string  `json:"command"`
	Description *string `json:"description"`
}

type BadgerLogger

type BadgerLogger struct {
	*log.Logger
}

BadgerLogger implements badger.Logger interface

func (*BadgerLogger) Debugf

func (l *BadgerLogger) Debugf(f string, v ...interface{})

func (*BadgerLogger) Errorf

func (l *BadgerLogger) Errorf(f string, v ...interface{})

func (*BadgerLogger) Infof

func (l *BadgerLogger) Infof(f string, v ...interface{})

func (*BadgerLogger) Warningf

func (l *BadgerLogger) Warningf(f string, v ...interface{})

type Config

type Config struct {
	Variables      map[string]interface{} `json:variables`
	StoreVariables bool                   `json:"store_variables"`
}

type DBService

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

DBService manages database access with proper locking

func GetDBService

func GetDBService() *DBService

GetDBService returns the singleton instance of DBService

func (*DBService) AutoCloseDB

func (s *DBService) AutoCloseDB(inactivityPeriod time.Duration)

AutoCloseDB sets up automatic DB closing after a period of inactivity

func (*DBService) CloseDB

func (s *DBService) CloseDB()

CloseDB explicitly closes the database - call this when the app is shutting down

func (*DBService) ReadOperation

func (s *DBService) ReadOperation(operation func(*Store) error) error

ReadOperation performs a read operation with timeout

func (*DBService) ReadOperationWithContext

func (s *DBService) ReadOperationWithContext(ctx context.Context, operation func(*Store) error) error

ReadOperationWithContext performs a read operation with context and timeout

func (*DBService) ReadOperationWithRetry

func (s *DBService) ReadOperationWithRetry(operation func(*Store) error, maxRetries int) error

ReadOperationWithRetry performs a read operation with retries

func (*DBService) WithTimeout

func (s *DBService) WithTimeout(duration time.Duration) *DBService

WithTimeout sets custom timeout for DB operations

func (*DBService) WriteOperation

func (s *DBService) WriteOperation(operation func(*Store) error) error

WriteOperation performs a write operation with timeout

type Store

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

Store represents a BadgerDB key-value store

func New

func New(db *badger.DB) *Store

New creates a new Store instance

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete removes a key

func (*Store) Get

func (s *Store) Get(key string, value interface{}) error

Get retrieves a value for a key

func (*Store) List

func (s *Store) List(prefix string) ([]string, error)

List returns all keys with a given prefix

func (*Store) Set

func (s *Store) Set(key string, value interface{}) error

Set stores a value for a key

type TemplateItem

type TemplateItem struct {
	Slug     string `json:"slug"`
	Workflow string `json:"workflow"`
}

func GetTemplateSafe

func GetTemplateSafe(slug string) (*TemplateItem, error)

GetTemplateSafe retrieves a template safely through the DB service

func ListTemplatesSafe

func ListTemplatesSafe() ([]TemplateItem, error)

ListTemplatesSafe lists templates safely through the DB service

type TemplateStoreManager

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

func NewTemplateStoreManager

func NewTemplateStoreManager(store *Store) *TemplateStoreManager

func (*TemplateStoreManager) CreateTemplate

func (ts *TemplateStoreManager) CreateTemplate(template TemplateItem) error

func (*TemplateStoreManager) DeleteTemplate

func (ts *TemplateStoreManager) DeleteTemplate(slug string) error

func (*TemplateStoreManager) ExportTemplate

func (ts *TemplateStoreManager) ExportTemplate(slug string) (string, error)

func (*TemplateStoreManager) GetTemplate

func (ts *TemplateStoreManager) GetTemplate(slug string) (*TemplateItem, error)

func (*TemplateStoreManager) ImportTemplate

func (ts *TemplateStoreManager) ImportTemplate(jsonData string) error

func (*TemplateStoreManager) ListTemplates

func (ts *TemplateStoreManager) ListTemplates() ([]TemplateItem, error)

func (*TemplateStoreManager) SearchTemplates

func (ts *TemplateStoreManager) SearchTemplates(query string) ([]TemplateItem, error)

func (*TemplateStoreManager) UpdateTemplate

func (ts *TemplateStoreManager) UpdateTemplate(template TemplateItem) error

type Workflow

type Workflow struct {
	ID          string          `json:"id"`
	Name        string          `json:"name"`
	PreChecks   []Atom          `json:"pre_checks"`
	Steps       []Atom          `json:"steps"`
	Description *string         `json:"description"`
	Actions     map[string]Atom `json:"actions"`
	Config      Config          `json:"config"`
	UsesSudo    bool            `json:"uses_sudo"`
}

func GetWorkflowSafe

func GetWorkflowSafe(id string) (*Workflow, error)

GetWorkflowSafe retrieves a workflow safely through the DB service

func ListWorkflowsSafe

func ListWorkflowsSafe() ([]Workflow, error)

ListWorkflowsSafe lists workflows safely through the DB service

type WorkflowStore

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

func NewWorkflowStore

func NewWorkflowStore(store *Store) *WorkflowStore

func (*WorkflowStore) AddStep

func (ws *WorkflowStore) AddStep(id string, step Atom) error

func (*WorkflowStore) CreateWorkflow

func (ws *WorkflowStore) CreateWorkflow(id string, workflow Workflow) error

func (*WorkflowStore) DeleteWorkflow

func (ws *WorkflowStore) DeleteWorkflow(id string) error

func (*WorkflowStore) ExportWorkflow

func (ws *WorkflowStore) ExportWorkflow(id string) (string, error)

func (*WorkflowStore) GetWorkflow

func (ws *WorkflowStore) GetWorkflow(id string) (*Workflow, error)

func (*WorkflowStore) ImportWorkflow

func (ws *WorkflowStore) ImportWorkflow(id string, jsonData string) error

func (*WorkflowStore) ListWorkflows

func (ws *WorkflowStore) ListWorkflows() ([]Workflow, error)

func (*WorkflowStore) RemoveStep

func (ws *WorkflowStore) RemoveStep(id string, index int) error

func (*WorkflowStore) SearchWorkflows

func (ws *WorkflowStore) SearchWorkflows(query string) ([]Workflow, error)

func (*WorkflowStore) UpdateConfig

func (ws *WorkflowStore) UpdateConfig(id string, configMap map[string]interface{}) error

func (*WorkflowStore) UpdateWorkflow

func (ws *WorkflowStore) UpdateWorkflow(id string, workflow Workflow) error

Jump to

Keyboard shortcuts

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