vars

package
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 6 Imported by: 0

README

Nexlayer Template Variables

This directory has been moved. Please refer to docs/schema/README.md for the definitive schema documentation, including template variables.

Documentation

Overview

Package vars provides centralized configuration management for the Nexlayer CLI. Deprecated: Use pkg/config instead.

Index

Constants

View Source
const (
	// PodReferenceVar represents pod reference variables like <pod-name>.pod
	PodReferenceVar = "pod-reference"

	// TemplateVar represents template variables like <% VAR_NAME %>
	TemplateVar = "template-var"

	// EnvVar represents environment variables
	EnvVar = "env-var"
)

Variable types

View Source
const (
	URLVar      = "URL"
	RegistryVar = "REGISTRY"
)

Common variables used in templates

View Source
const (
	// DefaultAPIURL is the default Nexlayer API endpoint
	DefaultAPIURL = "https://api.nexlayer.dev"

	// ConfigFileName is the name of the configuration file
	ConfigFileName = "config.yaml"

	// CacheDir is the directory for caching CLI data
	CacheDir = ".nexlayer"

	// DefaultPort is the default port for local development
	DefaultPort = 3000
)

Configuration constants

Variables

This section is empty.

Functions

func ExtractVariables

func ExtractVariables(input string) map[string]string

ExtractVariables finds all variable references in a string

func GetAPIURL

func GetAPIURL() string

GetAPIURL returns the configured API URL or the default

func GetCacheDir

func GetCacheDir() (string, error)

GetCacheDir returns the platform-specific cache directory

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the platform-specific configuration directory

func GetDefaultShell

func GetDefaultShell() string

GetDefaultShell returns the default shell for the current platform

func GetLogLevel

func GetLogLevel() string

GetLogLevel returns the configured log level

func GetProjectNamespace

func GetProjectNamespace() string

GetProjectNamespace returns the current project namespace

func GetRegistryConfig

func GetRegistryConfig() (string, string, string)

GetRegistryConfig returns the container registry configuration

func GetToken

func GetToken() string

GetToken returns the authentication token from environment or config

func GetUserAgent

func GetUserAgent() string

GetUserAgent returns the CLI user agent string

func IsDebug

func IsDebug() bool

IsDebug returns true if debug mode is enabled

func IsDevelopment

func IsDevelopment() bool

IsDevelopment returns true if running in development mode

func SubstitutePod

func SubstitutePod(pod interface{}, ctx *VariableContext) error

SubstitutePod replaces all variables in pod configuration

func SubstituteVariables

func SubstituteVariables(input string, ctx *VariableContext) (string, error)

SubstituteVariables replaces Nexlayer variables in a string

func ValidateConfig

func ValidateConfig() error

ValidateConfig checks if all required configuration is present

func ValidateSubstitution

func ValidateSubstitution(input string, ctx *VariableContext) ([]string, error)

ValidateSubstitution checks if all variables in a string can be substituted

Types

type Config

type Config struct {
	// API configuration
	API struct {
		URL   string `yaml:"url"`
		Token string `yaml:"token"`
	} `yaml:"api"`

	// Project configuration
	Project struct {
		Name      string `yaml:"name"`
		Namespace string `yaml:"namespace"`
		Domain    string `yaml:"domain"`
	} `yaml:"project"`

	// Registry configuration
	Registry struct {
		Type     string `yaml:"type"`     // Container registry type (ghcr, dockerhub, gcr, ecr, artifactory, gitlab)
		URL      string `yaml:"url"`      // Registry URL
		Username string `yaml:"username"` // Registry username
		Region   string `yaml:"region"`   // Registry region (for ECR)
		Project  string `yaml:"project"`  // Registry project ID (for GCR)
	} `yaml:"registry"`

	// Build configuration
	Build struct {
		Context string `yaml:"context"` // Docker build context path
		Tag     string `yaml:"tag"`     // Docker image tag
	} `yaml:"build"`

	// Environment variables
	Env map[string]string `yaml:"env"`
}

Config holds the CLI configuration

type VariableContext

type VariableContext struct {
	// Map of pod names to internal DNS names
	Pods map[string]string

	// Map of variable names to values
	Variables map[string]string

	// Registry URL for image references
	Registry string

	// Application URL
	URL string
}

VariableContext provides the context for variable substitution

func NewVariableContext

func NewVariableContext() *VariableContext

NewVariableContext creates a new variable context

func (*VariableContext) AddPod

func (c *VariableContext) AddPod(name string)

AddPod adds a pod to the context

func (*VariableContext) SetRegistry

func (c *VariableContext) SetRegistry(registry string)

SetRegistry sets the registry URL

func (*VariableContext) SetURL

func (c *VariableContext) SetURL(url string)

SetURL sets the application URL

func (*VariableContext) SetVariable

func (c *VariableContext) SetVariable(name, value string)

SetVariable sets a variable value

Jump to

Keyboard shortcuts

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