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
- Variables
- func AnyToString(value any) string
- func Copier(instance any, data any) error
- func Dedent(s string) string
- func In(value any, list ...any) bool
- func NameWithDefaultPrefix(name string, separator rune) string
- func NotIn(value any, list ...any) bool
- func Stringify(data interface{}) string
- func Ternary(condition bool, x, y any) any
- func ToPascalCase(input string) string
- func Trim(s string) string
Constants ¶
const ( DefaultProjectPrefix = "dm" TemplatesPath = "stacks" ArtifactsPath = "artifacts" TemplateExtension = ".yml" )
Defaults used throughout the CLI.
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.
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" )
const ( RelKindTable = "r" RelKindPartition = "p" RelKindView = "v" )
const ( SchemaCore = "core" SchemaView = "view" SchemaMart = "mart" )
Logical names of all schemas managed by the CLI.
const ( LayerRaw = "raw" LayerBronze = "bronze" LayerSilver = "silver" LayerGold = "gold" )
Logical names of all layers managed by the CLI.
Variables ¶
var Blue = color.New(color.FgBlue).SprintfFunc()
Blue prints formatted text in blue. Usage: fmt.Println(Blue("your message"))
var Green = color.New(color.FgGreen).SprintfFunc()
Green prints formatted text in green. Usage: fmt.Println(Green("your message"))
var Red = color.New(color.FgRed).SprintfFunc()
Red prints formatted text in red. Usage: fmt.Println(Red("your message"))
var Yellow = color.New(color.FgYellow).SprintfFunc()
Yellow prints formatted text in yellow. Usage: fmt.Println(Yellow("your message"))
Functions ¶
func AnyToString ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.