common

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = ""

Version is set via ldflags at build time: -ldflags "-X viiper/internal/codegen/common.Version=x.y.z"

Functions

func ExtractPrefix

func ExtractPrefix(name string) string

ExtractPrefix extracts the common prefix from a constant name for enum grouping Examples: "Key_A" -> "Key_", "ModifierShift" -> "Modifier", "LED1" -> "LED"

func FileHeader

func FileHeader(commentPrefix, langLabel string) string

FileHeader returns a standard two-line autogenerated header for generated files. commentPrefix is the line comment token for the target language (e.g., "//"). langLabel is a human readable language label to include (e.g., "TypeScript", "C#").

func GenerateLicense

func GenerateLicense(logger *slog.Logger, outputDir string) error

func GenerateReadme

func GenerateReadme(logger *slog.Logger, outputDir string) error

func GetVersion

func GetVersion() (string, error)

GetVersion returns the version string that was set at build time via ldflags. Returns "0.0.1-dev" if Version is empty (development builds only). For production releases, Version MUST be set via: go build -ldflags "-X viiper/internal/codegen/common.Version=x.y.z"

func NormalizeGoType

func NormalizeGoType(goType string) (base string, isSlice bool, isPointer bool)

NormalizeGoType strips pointer and slice prefixes from a Go type string and reports whether the original type was a slice or pointer. Examples: "*MyType" -> ("MyType", false, true), "[]uint8" -> ("uint8", true, false)

func ParseVersion

func ParseVersion(version string) (major, minor, patch int)

ParseVersion extracts major, minor, patch from version string like "1.2.3" or "1.2.3-dirty" Returns major, minor, patch as integers.

func SanitizeLeadingDigit

func SanitizeLeadingDigit(name string) string

SanitizeLeadingDigit prefixes names that start with a digit with "Num" to keep identifiers valid in target languages.

func SortedStringKeys

func SortedStringKeys(m map[string]any) []string

SortedStringKeys returns the sorted keys of a map[string]any.

func ToCamelCase

func ToCamelCase(s string) string

func ToPascalCase

func ToPascalCase(s string) string

func ToSnakeCase

func ToSnakeCase(s string) string

func TrimPrefixAndSanitize

func TrimPrefixAndSanitize(full string) (prefix, member string)

TrimPrefixAndSanitize splits a constant full name into its enum prefix and member, and sanitizes the member (e.g., leading digits -> "Num..."). Example: "Key_1" => ("Key_", "Num1"), "ModifierShift" => ("Modifier", "Shift").

Types

This section is empty.

Jump to

Keyboard shortcuts

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