Skip to main content

dashboard.go

Filename: dashboard.go

  1. Overview

This file defines the data structures and related methods for dashboards, rules, planned maintenance, and TTL settings used within the application. It includes definitions for database models, data serialization, and slug generation.

  1. Detailed Documentation

type Dashboard

  • Purpose: Represents a dashboard with its metadata and data. It includes fields for database interaction, auditing, and data storage.
  • Fields:
    • bun.BaseModel: Embedded struct for Bun ORM integration.
    • TimeAuditable: Embedded struct for time-related auditing fields.
    • UserAuditable: Embedded struct for user-related auditing fields.
    • OrgID string: The organization ID the dashboard belongs to.
    • ID int: The unique identifier of the dashboard.
    • UUID string: The unique identifier of the dashboard.
    • Data DashboardData: The dashboard's data, stored as a map of string to interface{}.
    • Locked *int: A flag indicating whether the dashboard is locked.
    • Slug string: A URL-friendly slug generated from the dashboard title.
    • Title string: The title of the dashboard.
  • Returns: None

func (d *Dashboard) UpdateSlug()

  • Purpose: Updates the Slug field of the Dashboard struct based on the title key present in the Data field.
  • Parameters: None
  • Returns: None

func SlugifyTitle(title string) string

  • Purpose: Generates a URL-friendly slug from a given title. If the title cannot be slugified, it encodes the title using base64.
  • Parameters:
    • title string: The title to slugify.
  • Returns: string: The generated slug.

type DashboardData

  • Purpose: Defines a custom type DashboardData as a map[string]interface{} for storing dashboard data, and implements the driver.Valuer and sql.Scanner interfaces for database interaction.
  • Type: map[string]interface{}
  • Methods:
    • Value() (driver.Value, error): Returns the JSON-encoded value of the DashboardData map for database storage.
    • Scan(src interface{}) error: Scans a value from the database and unmarshals it into the DashboardData map.
  • Returns: None

func (c DashboardData) Value() (driver.Value, error)

  • Purpose: Marshals the DashboardData into a JSON format for database storage.
  • Parameters: None
  • Returns:
    • driver.Value: The JSON-encoded representation of the DashboardData.
    • error: An error, if any occurred during the marshaling process.

func (c *DashboardData) Scan(src interface{}) error

  • Purpose: Unmarshals data from the database into the DashboardData.
  • Parameters:
    • src interface{}: The source data from the database (either a byte slice or a string).
  • Returns:
    • error: An error, if any occurred during the unmarshaling process.

type Rule

  • Purpose: Represents a rule with its metadata and data. It includes fields for database interaction and auditing.
  • Fields:
    • bun.BaseModel: Embedded struct for Bun ORM integration.
    • ID int: The unique identifier of the rule.
    • CreatedAt time.Time: The time the rule was created.
    • CreatedBy string: The user who created the rule.
    • UpdatedAt time.Time: The time the rule was last updated.
    • UpdatedBy string: The user who last updated the rule.
    • Deleted int: A flag indicating whether the rule is deleted.
    • Data string: The rule's data, stored as a string.
  • Returns: None

type PlannedMaintenance

  • Purpose: Represents a planned maintenance event with its metadata. It includes fields for database interaction and auditing.
  • Fields:
    • bun.BaseModel: Embedded struct for Bun ORM integration.
    • ID int: The unique identifier of the planned maintenance event.
    • Name string: The name of the planned maintenance event.
    • Description string: A description of the planned maintenance event.
    • AlertIDs string: A comma-separated list of alert IDs associated with the planned maintenance event.
    • Schedule string: The schedule of the planned maintenance event.
    • CreatedAt time.Time: The time the planned maintenance event was created.
    • CreatedBy string: The user who created the planned maintenance event.
    • UpdatedAt time.Time: The time the planned maintenance event was last updated.
    • UpdatedBy string: The user who last updated the planned maintenance event.
  • Returns: None

type TTLSetting

  • Purpose: Represents a Time-To-Live (TTL) setting for data retention.
  • Fields:
    • bun.BaseModel: Embedded struct for Bun ORM integration.
    • Identifiable: Embedded struct (definition not in this file).
    • TimeAuditable: Embedded struct for time-related auditing fields.
    • TransactionID string: The ID of the transaction associated with the TTL setting.
    • TableName string: The name of the table to which the TTL setting applies.
    • TTL int: The TTL value.
    • ColdStorageTTL int: The TTL value for cold storage.
    • Status string: The status of the TTL setting.
    • OrgID string: The organization ID the TTL setting belongs to.
  • Returns: None
  1. Code Examples

Not applicable, as the code primarily defines data structures and database interactions.

  1. Clarity and Accuracy

The documentation accurately reflects the code's functionality.

  1. Markdown & MDX Perfection

The markdown syntax is correct and properly formatted.

  1. Edge Cases To Avoid Breaking MDX:

No issues found.

  1. Getting Started Relevance

Include in Getting Started: NO