handler

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatJSON  = "json"
	FormatYAML  = "yaml"
	FormatTable = "table"
)

Format constants

View Source
const (
	ParamCluster      = "cluster"
	ParamNamespace    = "namespace"
	ParamProject      = "project"
	ParamFormat       = "format"
	ParamName         = "name"
	ParamUser         = "user"
	ParamContainer    = "container"
	ParamTailLines    = "tailLines"
	ParamSinceSeconds = "sinceSeconds"
	ParamTimestamps   = "timestamps"
	ParamPrevious     = "previous"
	ParamKeyword      = "keyword"
	// Kubernetes toolset parameters
	ParamKind          = "kind"
	ParamLabelSelector = "labelSelector"
	ParamLimit         = "limit"
	ParamResource      = "resource"
	ParamPatch         = "patch"
	ParamPage          = "page"
	ParamFieldSelector = "fieldSelector"
)

Parameter name constants

Variables

View Source
var (
	ErrRancherNotConfigured = errors.New("rancher client not configured, please configure rancher credentials to use this tool")
	ErrSteveNotConfigured   = errors.New("kubernetes client not configured, please configure rancher credentials to use this tool")
	ErrInvalidFormat        = errors.New("invalid output format")
	ErrMissingParameter     = errors.New("missing required parameter")
	ErrReadOnlyMode         = errors.New("operation not allowed: server is running in read-only mode")
	ErrDestructiveDisabled  = errors.New("operation not allowed: destructive operations are disabled")
)

Error definitions

Functions

func ApplyPagination

func ApplyPagination[T any](items []T, limit, page int64) ([]T, int64)

ApplyPagination applies limit and page to a slice, returns paginated slice and total count.

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to a boolean value

func DefaultFilterPaths

func DefaultFilterPaths() []string

DefaultFilterPaths returns recommended default filter paths for reducing output verbosity. Users can use these as a starting point for their configuration.

func ExtractAndValidateFormat

func ExtractAndValidateFormat(params map[string]interface{}) (string, error)

ExtractAndValidateFormat extracts format parameter and validates it. Returns validated format or error if format is invalid.

func ExtractBool

func ExtractBool(params map[string]interface{}, key string, defaultValue bool) bool

ExtractBool extracts a boolean parameter with a default value

func ExtractFormat

func ExtractFormat(params map[string]interface{}) string

ExtractFormat extracts the format parameter with "json" as default.

func ExtractInt64

func ExtractInt64(params map[string]interface{}, key string, defaultValue int64) int64

ExtractInt64 extracts an int64 parameter with a default value

func ExtractOptionalInt64

func ExtractOptionalInt64(params map[string]interface{}, key string) *int64

ExtractOptionalInt64 extracts an optional int64 parameter

func ExtractOptionalString

func ExtractOptionalString(params map[string]interface{}, key string) string

ExtractOptionalString extracts an optional string parameter. Returns empty string if the parameter is missing or empty.

func ExtractOptionalStringWithDefault

func ExtractOptionalStringWithDefault(params map[string]interface{}, key, defaultValue string) string

ExtractOptionalStringWithDefault extracts an optional string parameter with a default value. Returns defaultValue if the parameter is missing or empty.

func ExtractRequiredString

func ExtractRequiredString(params map[string]interface{}, key string) (string, error)

ExtractRequiredString extracts a required string parameter from params map. Returns ErrMissingParameter if the parameter is missing or empty.

func FilterFields

func FilterFields(data []map[string]string, fields []string) []map[string]string

FilterFields filters map data to include only specified fields If fields is nil or empty, returns data unchanged

func FormatAsJSON

func FormatAsJSON(data interface{}) (string, error)

FormatAsJSON formats data as JSON

func FormatAsTable

func FormatAsTable(data []map[string]string, headers []string) string

FormatAsTable formats data as a table with headers

func FormatAsYAML

func FormatAsYAML(data interface{}) (string, error)

FormatAsYAML formats data as YAML

func FormatEmptyResult

func FormatEmptyResult(format string) (string, error)

FormatEmptyResult formats an empty result based on the output format.

func FormatOutput

func FormatOutput(data []map[string]string, format string, headers []string, fields []string) (string, error)

FormatOutput is a generic helper for formatting slice data in different output formats. It reduces code duplication across handlers by consolidating the format switch logic. If fields is provided, only those fields will be included in the output.

func FormatSingleResult

func FormatSingleResult(data map[string]interface{}, format string, tableHeaders ...string) (string, error)

FormatSingleResult formats a single result object (map[string]interface{}) in the specified format. This is useful for get handlers that return a single resource. tableHeaders is optional - if provided and format is "table", it renders a table with those fields.

func FormatTime

func FormatTime(timestamp string) string

FormatTime formats time for display. Returns "-" for empty timestamps.

func FormatWithFields

func FormatWithFields(data []map[string]string, fields []string, format string) (string, error)

FormatWithFields formats data with specific fields only If fields is empty, includes all fields

func GetStringValue

func GetStringValue(v interface{}) string

GetStringValue extracts string value from interface safely. Returns "-" for nil values.

func ResolveCluster

func ResolveCluster(ctx context.Context, client *norman.Client, params map[string]interface{}) (string, error)

ResolveCluster extracts cluster parameter and resolves it via fuzzy lookup Supports: exact ID, exact name, or partial name match Returns the resolved cluster ID

func ResolveOptionalCluster

func ResolveOptionalCluster(ctx context.Context, client *norman.Client, params map[string]interface{}) (string, error)

ResolveOptionalCluster extracts optional cluster parameter and resolves it via fuzzy lookup Returns empty string if cluster is not specified Supports: exact ID, exact name, or partial name match

func ResolveOptionalProject

func ResolveOptionalProject(ctx context.Context, client *norman.Client, params map[string]interface{}, clusterID string) (string, error)

ResolveOptionalProject extracts optional project parameter and resolves it via fuzzy lookup Returns empty string if project is not specified Supports: exact ID, exact name, or partial name match

func ValidateFormat

func ValidateFormat(format string) error

ValidateFormat validates that the format is one of the supported formats

Types

type ResourceFilter

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

ResourceFilter provides configurable filtering for Kubernetes resources. It removes specified fields from resources based on user-configured paths.

func NewResourceFilter

func NewResourceFilter(paths []string) *ResourceFilter

NewResourceFilter creates a new ResourceFilter with the specified paths.

func NewResourceFilterFromParams

func NewResourceFilterFromParams(params map[string]interface{}) *ResourceFilter

NewResourceFilterFromParams creates a ResourceFilter from handler params. Returns nil if no filters are configured.

func (*ResourceFilter) Filter

Filter removes the configured fields from a resource and returns a cleaned copy. The original resource is not modified.

func (*ResourceFilter) FilterList

FilterList applies filtering to all resources in a list.

Jump to

Keyboard shortcuts

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