util

package
v0.13.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AddonNone       = "none" // Special value for no add-ons
	AddonTimeSeries = "time-series"
	AddonAI         = "ai"
)

Addon constants - these match the ServiceCreateAddons from the API

Variables

This section is empty.

Functions

func AnySlice

func AnySlice[T any](in []T) []any

func ConvertStringSlicePtr added in v0.9.0

func ConvertStringSlicePtr[T ~string](ss []string) *[]T

ConvertStringSlicePtr converts a slice of strings to a pointer to another string-like type. Returns nil if the input slice is nil.

func Deref

func Deref[T any](val *T) T

func DerefStr

func DerefStr[T ~string](val *T) string

func ExpandPath added in v0.4.0

func ExpandPath(path string) string

ExpandPath expands environment variables and tilde in file paths. It handles: - Empty paths (returns empty string) - Environment variable expansion (e.g., $HOME/config) - Home directory expansion (e.g., ~/config or ~) - Path normalization for cross-platform compatibility

func GenerateServiceName

func GenerateServiceName() string

Matches front-end logic for generating a random service name

func IsCI added in v0.10.0

func IsCI() bool

IsCI determines if the current execution context is within a known CI/CD system. This is based on https://github.com/watson/ci-info/blob/HEAD/index.js.

func IsTerminal added in v0.10.0

func IsTerminal(w io.Writer) bool

IsTerminal is a helper method for detecting whether an io.Writer is a interactive terminal / TTY.

func IsValidAddon added in v0.1.2

func IsValidAddon(addon string) bool

IsValidAddon checks if the given add-on is valid (case-sensitive as per API spec)

func Must

func Must[T any](v T, err error) T

func ParseCPUMemory

func ParseCPUMemory(cpuMemoryStr string) (string, string, error)

ParseCPUMemory parses a CPU/memory combination string (e.g., "2 CPU/8GB") and returns millicores and GB. If "shared" is given, returns "shared" for both CPU and memory.

func Ptr

func Ptr[T any](val T) *T

func SerializeToJSON added in v0.10.0

func SerializeToJSON(w io.Writer, v any) error

func SerializeToYAML added in v0.10.0

func SerializeToYAML(w io.Writer, v any, omitNull bool) error

func ValidAddons added in v0.1.2

func ValidAddons() []string

ValidAddons returns a slice of all valid add-on values

func ValidateAddons added in v0.1.2

func ValidateAddons(addons []string) ([]string, error)

ValidateAddons validates a slice of add-ons and removes duplicate values

func ValidateAndNormalizeCPUMemory

func ValidateAndNormalizeCPUMemory(cpuMillis, memoryGBs string) (*string, *string, error)

ValidateAndNormalizeCPUMemory validates CPU/Memory values and applies auto-configuration logic

Types

type CPUMemoryConfig

type CPUMemoryConfig struct {
	Shared    bool // Shared CPU/Memory
	CPUMillis int  // CPU in millicores
	MemoryGBs int  // Memory in GB
}

CPUMemoryConfig represents an allowed CPU/Memory configuration

func (*CPUMemoryConfig) Matches added in v0.9.0

func (c *CPUMemoryConfig) Matches(cpuMillis, memoryGBs string) (string, string, bool)

func (*CPUMemoryConfig) String

func (c *CPUMemoryConfig) String() string

type CPUMemoryConfigs

type CPUMemoryConfigs []CPUMemoryConfig

func GetAllowedCPUMemoryConfigs

func GetAllowedCPUMemoryConfigs() CPUMemoryConfigs

GetAllowedCPUMemoryConfigs returns the allowed CPU/Memory configurations from the spec

func (CPUMemoryConfigs) String

func (c CPUMemoryConfigs) String() string

String returns a user-friendly string of allowed CPU/Memory combinations

func (CPUMemoryConfigs) Strings

func (c CPUMemoryConfigs) Strings() []string

Strings returns a slice of user-friendly strings of allowed CPU/Memory combinations

Jump to

Keyboard shortcuts

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