validation

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package validation provides validation functions for various configuration types.

Package validation provides validation services for the Narvana platform.

Package validation provides validation functions for various configuration types.

Index

Constants

View Source
const MaxEnvKeyLength = 256

MaxEnvKeyLength is the maximum allowed length for an environment variable key.

View Source
const MaxEnvValueLength = 32 * 1024

MaxEnvValueLength is the maximum allowed length for an environment variable value (32KB).

Variables

View Source
var DefaultDatabaseVersions = map[string]string{
	"postgres": "16",
	"mysql":    "8.4",
	"mariadb":  "11.4",
	"mongodb":  "7.0",
	"redis":    "7.2",
	"sqlite":   "3",
}

DefaultDatabaseVersions defines the default version for each database type.

View Source
var SupportedDatabaseTypes = map[string][]string{
	"postgres": {"14", "15", "16"},
	"mysql":    {"8.0", "8.4"},
	"mariadb":  {"10.11", "11.4"},
	"mongodb":  {"6.0", "7.0"},
	"redis":    {"7.0", "7.2"},
	"sqlite":   {"3"},
}

SupportedDatabaseTypes defines the supported database types and their versions.

Functions

func FormatBuildTags

func FormatBuildTags(tags []string) string

FormatBuildTags formats build tags as a comma-separated string for the -tags flag. Requirements: 17.2, 17.3

Returns an empty string if no tags are provided.

func GetDefaultVersion

func GetDefaultVersion(dbType string) string

GetDefaultVersion returns the default version for a database type.

func GetSupportedVersions

func GetSupportedVersions(dbType string) []string

GetSupportedVersions returns the supported versions for a database type.

func HasLdflagsVariables

func HasLdflagsVariables(ldflags string) bool

HasLdflagsVariables checks if the ldflags string contains any substitution variables. Returns true if any of ${version}, ${commit}, or ${buildTime} are present.

func IsSupportedDatabaseType

func IsSupportedDatabaseType(dbType string) bool

IsSupportedDatabaseType checks if a database type is supported.

func SubstituteLdflagsVariables

func SubstituteLdflagsVariables(ldflags string, ctx LdflagsBuildContext) string

SubstituteLdflagsVariables replaces placeholder variables in ldflags with actual values. Supported variables:

  • ${version} - replaced with the application version
  • ${commit} - replaced with the git commit hash
  • ${buildTime} - replaced with the build timestamp in RFC3339 format

**Validates: Requirements 18.3**

func ValidateBuildTag

func ValidateBuildTag(tag string) error

ValidateBuildTag validates a single Go build tag. Requirements: 17.5

Build tag rules: - Cannot be empty - Cannot contain spaces - Can only contain alphanumeric characters, underscores, and dots

func ValidateBuildTags

func ValidateBuildTags(tags []string) error

ValidateBuildTags validates a slice of Go build tags. Requirements: 17.5

Returns an error if any tag is invalid.

func ValidateCPU

func ValidateCPU(cpu string) error

ValidateCPU validates a CPU specification string.

func ValidateDatabaseConfig

func ValidateDatabaseConfig(config *models.DatabaseConfig) error

ValidateDatabaseConfig validates a database configuration. Requirements: 29.1, 29.2

func ValidateEnvKey

func ValidateEnvKey(key string) error

ValidateEnvKey validates that an environment variable key is valid. Requirements: 5.1, 5.2

Environment variable key rules: - Must not be empty - Must start with a letter (A-Z, a-z) or underscore (_) - Can contain letters, numbers, and underscores - Must not exceed 256 characters

func ValidateEnvValue

func ValidateEnvValue(value string) error

ValidateEnvValue validates that an environment variable value is valid. Requirements: 5.1, 5.3

Environment variable value rules: - Must not exceed 32KB

func ValidateLdflags

func ValidateLdflags(ldflags string) error

ValidateLdflags performs basic validation on ldflags string. Currently this is a permissive validation that allows most ldflags formats. Returns nil if valid, or an error describing the issue.

func ValidateMemory

func ValidateMemory(memory string) error

ValidateMemory validates a memory specification string.

func ValidateResourceSpec

func ValidateResourceSpec(spec *models.ResourceSpec) error

ValidateResourceSpec validates a resource specification. Requirements: 12.2

CPU format: decimal numbers like "0.5", "1", "2" Memory format: numbers with unit suffix like "256Mi", "1Gi"

func ValidateServiceName

func ValidateServiceName(name string) error

ValidateServiceName validates that a service name is a valid DNS label. Requirements: 10.1, 10.2, 10.3

DNS label rules: - Must be 1-63 characters long - Must start with a lowercase letter - Can contain lowercase letters, numbers, and hyphens - Cannot start or end with a hyphen

Types

type DependencyValidator

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

DependencyValidator validates service dependencies for cycles and self-references.

func NewDependencyValidator

func NewDependencyValidator(logger *slog.Logger) *DependencyValidator

NewDependencyValidator creates a new DependencyValidator.

func (*DependencyValidator) ValidateDependencies

func (v *DependencyValidator) ValidateDependencies(services []models.ServiceConfig, targetService string, newDeps []string) error

ValidateDependencies checks for cycles and self-dependencies in the service dependency graph. It validates that adding newDeps to targetService won't create a cycle. Requirements: 9.1, 9.3, 9.4

type LdflagsBuildContext

type LdflagsBuildContext struct {
	Version   string    // Application version (e.g., "1.0.0", "v2.3.4")
	Commit    string    // Git commit hash (short or full)
	BuildTime time.Time // Build timestamp
}

LdflagsBuildContext contains build-time values for ldflags variable substitution. **Validates: Requirements 18.3**

func DefaultLdflagsBuildContext

func DefaultLdflagsBuildContext() LdflagsBuildContext

DefaultLdflagsBuildContext returns a build context with default values. This is useful when actual build context is not available.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a validation error with field context.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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