api

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheKeyPrefixIncidents      = "incidents"
	CacheKeyPrefixAlerts         = "alerts"
	CacheKeyPrefixIncidentDetail = "incident_detail"
	CacheKeyPrefixAlertDetail    = "alert_detail"
)

Cache key prefixes

View Source
const DefaultCacheTTL = 5 * time.Minute

DefaultCacheTTL is the default cache duration

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	ID           string
	ShortID      string
	Summary      string
	Description  string
	Status       string
	Source       string
	CreatedAt    time.Time
	UpdatedAt    time.Time
	StartedAt    *time.Time
	EndedAt      *time.Time
	ExternalURL  string
	Services     []string
	Environments []string
	Groups       []string
	Labels       map[string]string
	// Detail fields (populated by GetAlert)
	Responders   []string
	Urgency      string
	DetailLoaded bool
}

func MockAlerts

func MockAlerts() []Alert

MockAlerts returns sample alert data for testing

type AlertsResult

type AlertsResult struct {
	Alerts     []Alert
	Pagination PaginationInfo
}

AlertsResult contains alerts and pagination info

type Cache

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

Cache provides a simple TTL-based in-memory cache

func NewCache

func NewCache(ttl time.Duration) *Cache

NewCache creates a new cache with the given TTL

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all items from the cache

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes an item from the cache

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, bool)

Get retrieves an item from the cache Returns the value and true if found and not expired, nil and false otherwise

func (*Cache) Set

func (c *Cache) Set(key string, value interface{})

Set stores an item in the cache

type CacheKeyBuilder

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

CacheKeyBuilder builds cache keys from parameters

func NewCacheKey

func NewCacheKey(prefix string) *CacheKeyBuilder

NewCacheKey creates a new cache key builder

func (*CacheKeyBuilder) Build

func (b *CacheKeyBuilder) Build() string

Build generates the cache key string Format: "prefix:key1=value1:key2=value2" (sorted by key)

func (*CacheKeyBuilder) With

func (b *CacheKeyBuilder) With(key string, value interface{}) *CacheKeyBuilder

With adds a parameter to the cache key

type Client

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

func NewClient

func NewClient(cfg *config.Config) (*Client, error)

func (*Client) ClearCache

func (c *Client) ClearCache()

ClearCache clears all cached data

func (*Client) Close

func (c *Client) Close() error

Close closes the client and releases resources

func (*Client) GetAlert

func (c *Client) GetAlert(ctx context.Context, id string, updatedAt time.Time) (*Alert, error)

GetAlert fetches detailed alert data by ID updatedAt is used for cache invalidation - cache key includes it so changes invalidate the cache

func (*Client) GetIncident

func (c *Client) GetIncident(ctx context.Context, id string, updatedAt time.Time) (*Incident, error)

GetIncident fetches detailed incident data by ID updatedAt is used for cache invalidation - cache key includes it so changes invalidate the cache

func (*Client) ListAlerts

func (c *Client) ListAlerts(ctx context.Context, page int) (*AlertsResult, error)

func (*Client) ListIncidents

func (c *Client) ListIncidents(ctx context.Context, page int) (*IncidentsResult, error)

func (*Client) ValidateAPIKey

func (c *Client) ValidateAPIKey(ctx context.Context) error

type Incident

type Incident struct {
	ID              string
	SequentialID    string
	Title           string
	Summary         string
	Status          string
	Severity        string
	Kind            string
	CreatedAt       time.Time
	UpdatedAt       time.Time
	StartedAt       *time.Time
	DetectedAt      *time.Time
	AcknowledgedAt  *time.Time
	MitigatedAt     *time.Time
	ResolvedAt      *time.Time
	Services        []string
	Environments    []string
	Teams           []string
	SlackChannelURL string
	JiraIssueURL    string
	// Detail fields (populated by GetIncident)
	URL              string
	ShortURL         string
	Causes           []string
	IncidentTypes    []string
	Functionalities  []string
	Roles            []IncidentRole
	CommanderName    string
	CommunicatorName string
	CreatedByName    string
	CreatedByEmail   string
	DetailLoaded     bool
}

func MockIncidents

func MockIncidents() []Incident

MockIncidents returns sample incident data for testing

type IncidentRole

type IncidentRole struct {
	Name      string
	UserName  string
	UserEmail string
}

type IncidentsResult

type IncidentsResult struct {
	Incidents  []Incident
	Pagination PaginationInfo
}

IncidentsResult contains incidents and pagination info

type PaginationInfo

type PaginationInfo struct {
	CurrentPage int
	HasNext     bool
	HasPrev     bool
}

PaginationInfo contains pagination state

type PersistentCache

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

PersistentCache provides a TTL-based cache backed by BoltDB

func NewPersistentCache

func NewPersistentCache(ttl time.Duration) (*PersistentCache, error)

NewPersistentCache creates a new persistent cache at ~/.rootly-tui/cache.db

func (*PersistentCache) Cleanup

func (c *PersistentCache) Cleanup()

Cleanup removes expired entries from the cache

func (*PersistentCache) Clear

func (c *PersistentCache) Clear()

Clear removes all items from the cache

func (*PersistentCache) Close

func (c *PersistentCache) Close() error

Close closes the database connection

func (*PersistentCache) Delete

func (c *PersistentCache) Delete(key string)

Delete removes an item from the cache

func (*PersistentCache) Get

func (c *PersistentCache) Get(key string) (interface{}, bool)

Get retrieves an item from the cache

func (*PersistentCache) GetTyped

func (c *PersistentCache) GetTyped(key string, dest interface{}) bool

GetTyped retrieves and unmarshals an item from the cache

func (*PersistentCache) Set

func (c *PersistentCache) Set(key string, value interface{})

Set stores an item in the cache

Jump to

Keyboard shortcuts

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