misc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package misc provides utility constants and helper functions used across the Data Master project.

It includes reusable logic for common tasks such as string checks, ternary operations, ANSI color formatting, and global layer identifiers (e.g., raw, bronze, silver, gold).

This package serves as a lightweight support layer for both CLI tools and processing components, helping to reduce code duplication and centralize generic behavior.

Index

Constants

View Source
const (
	DefaultProjectPrefix = "dm"
	TemplatesPath        = "stacks"
	ArtifactsPath        = "artifacts"
	TemplateExtension    = ".yml"
)

Defaults used throughout the CLI.

View Source
const (
	StackNameNetwork       = "network"
	StackNameRoles         = "roles"
	StackNameSecurity      = "security"
	StackNameDatabase      = "database"
	StackNameStorage       = "storage"
	StackNameRepositories  = "repositories"
	StackNameCatalog       = "catalog"
	StackNameGovernance    = "governance"
	StackNameConsumption   = "consumption"
	StackNameControl       = "control"
	StackNameFunctions     = "functions"
	StackNameStreaming     = "streaming"
	StackNameIngestion     = "ingestion"
	StackNameProcessing    = "processing"
	StackNameAnalytics     = "analytics"
	StackNameObservability = "observability"
	StackNameBenchmark     = "benchmark"
)

Logical names of all stacks managed by the CLI.

View Source
const (
	MigrationCoreScript = "database/migrations/001_create_dm_core.sql"
	MigrationViewScript = "database/migrations/002_create_dm_view.sql"
	MigrationMartScript = "database/migrations/003_create_dm_mart.sql"
)
View Source
const (
	RelKindTable     = "r"
	RelKindPartition = "p"
	RelKindView      = "v"
)
View Source
const (
	SchemaCore = "core"
	SchemaView = "view"
	SchemaMart = "mart"
)

Logical names of all schemas managed by the CLI.

View Source
const (
	LayerRaw    = "raw"
	LayerBronze = "bronze"
	LayerSilver = "silver"
	LayerGold   = "gold"
)

Logical names of all layers managed by the CLI.

Variables

View Source
var Blue = color.New(color.FgBlue).SprintfFunc()

Blue prints formatted text in blue. Usage: fmt.Println(Blue("your message"))

View Source
var Green = color.New(color.FgGreen).SprintfFunc()

Green prints formatted text in green. Usage: fmt.Println(Green("your message"))

View Source
var Red = color.New(color.FgRed).SprintfFunc()

Red prints formatted text in red. Usage: fmt.Println(Red("your message"))

View Source
var Yellow = color.New(color.FgYellow).SprintfFunc()

Yellow prints formatted text in yellow. Usage: fmt.Println(Yellow("your message"))

Functions

func AnyToString

func AnyToString(value any) string

AnyToString converts a generic value to its string representation.

Parameters:

  • value: a value of any supported type.

Returns:

  • string: the string representation of the input value.

Supported types:

  • Integer types (int, int8, int16, int32, int64)
  • Unsigned integers (uint, uint8, uint16, uint32, uint64)
  • Floating-point numbers (float32, float64)
  • Booleans
  • Strings and []byte
  • []string (joined with commas)
  • Nullable types (null.String, sql.NullString, null.Time)
  • time.Time
  • UUIDs (uuid.UUID and *uuid.UUID)
  • nil (returns empty string)
  • Other types are converted using Stringify (fallback).

func Copier

func Copier(instance any, data any) error

Copier copies data from a source into a target instance by marshaling to JSON and unmarshaling.

Parameters:

  • instance: any - The target instance to populate (must be a pointer).
  • data: any - The source data to copy from.

Returns:

  • error: an error if the copy operation fails, or nil if successful.

func Dedent

func Dedent(s string) string

Dedent removes common leading whitespace from every line of the input string. This is typically used for multi-line strings defined inline in code.

It finds the smallest indentation (spaces or tabs) among all non-empty lines and removes that indentation from every line.

Example:

input := `
    line 1
    line 2
`
output := Dedent(input)

Returns:

  • string: dedented version of the input.

func In

func In(value any, list ...any) bool

In checks whether a given value exists within a list of values.

Parameters:

  • value: the target value to search for.
  • list: a variadic list of values to search within.

Returns:

  • bool: true if the value is found in the list; false otherwise.

func NameWithDefaultPrefix

func NameWithDefaultPrefix(name string, separator rune) string

NameWithDefaultPrefix prepends the default project prefix to a name using the given separator.

Parameters:

  • name: string - The name to be prefixed.
  • separator: rune - The character used to separate the prefix and the name.

Returns:

  • string: A string in the format "<prefix><separator><name>".

func NotIn

func NotIn(value any, list ...any) bool

NotIn checks if a value is not present in the provided list.

Parameters:

  • value: any - The value to check.
  • list: ...any - A variadic list of values to compare against.

Returns:

  • bool: true if value is not in the list; false otherwise.

func Stringify

func Stringify(data interface{}) string

Stringify converts any Go data structure to its string representation.

If the input is already a string, it returns the value directly. Otherwise, it marshals the data to a JSON-formatted string.

Parameters:

  • data: interface{} - The value to stringify.

Returns:

  • string: The string or JSON-encoded representation of the input.

Panics:

  • If the data cannot be marshaled to JSON, the function will panic.

func Ternary

func Ternary(condition bool, x, y any) any

Ternary returns one of two values based on a boolean condition.

This function mimics the ternary (conditional) operator found in other languages, returning `x` if the condition is true, or `y` otherwise. It accepts any type as input and returns an interface{} (`any`), so the caller is responsible for type assertion if needed.

Parameters:

  • condition: boolean expression to evaluate.
  • x: value returned if the condition is true.
  • y: value returned if the condition is false.

Returns:

  • any: `x` if condition is true; otherwise `y`.

func ToPascalCase

func ToPascalCase(input string) string

ToPascalCase converts a kebab-case string into PascalCase.

Parameters:

  • input: string - The input string in kebab-case format (e.g., "my-variable-name").

Returns:

  • string: The resulting string in PascalCase format (e.g., "MyVariableName").

func Trim

func Trim(s string) string

Trim removes leading/trailing whitespace from the input string, after first removing any common indentation using Dedent.

It is useful for formatting multi-line string literals where indentation is used for code readability but should not be preserved.

Example:

input := `
    SELECT *
    FROM users
`
cleaned := Trim(input)

Returns:

  • string: trimmed and dedented version of the input.

Types

This section is empty.

Jump to

Keyboard shortcuts

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