common

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNoResources        string = "didn't get any collected resources"
	ErrNoHostArg          string = "didn't get any host arg"
	ErrMissingRquiredArg  string = "missing required arg"
	ErrCreatingConnection string = "fail to create a connection from service %v"
)
View Source
const (
	OutputSectionSep = "\n-------------------------------------------------------------------\n"
	ShortSep         = "\n-------------------------\n"

	CommaSeparator      string = ","
	CommaSpaceSeparator string = ", "
	NewLine             string = "\n"
	Tab                 string = "\t"

	Space = " "

	AnalyzedConnectivityHeader = "Analyzed connectivity:"

	AnyStr = "ANY" // ANY can specify any service or any src/dst in DFW rules

)

Variables

View Source
var AllEndpointsStr = JoinStringifiedSlice(allEndpoints, CommaSeparator)
View Source
var AllFormatsStr = JoinStringifiedSlice(allFormats, CommaSeparator)
View Source
var AllLogLevelOptionsStr = JoinStringifiedSlice(allLogLevelOptions, CommaSeparator)
View Source
var AllSegmentOptionsStr = JoinStringifiedSlice(allSegmentOptions, CommaSeparator)
View Source
var Update = flag.Bool("update", false, "write or override golden files")

a flag for writing/overriding the golden result files for tests

Functions

func CleanStr

func CleanStr(str string) string

CleanStr for comparison that should be insensitive to line comparators; cleaning strings from line comparators

func CustomStrSliceToStrings

func CustomStrSliceToStrings[S any](slice []S, f func(s S) string) []string

func CustomStrsSliceToStrings

func CustomStrsSliceToStrings[S any](slice []S, f func(s S) []string) []string

func FileExist

func FileExist(path string) bool

func GenerateTableString

func GenerateTableString(header []string, lines [][]string, opts *TableOptions) string

GenerateTableString returns a string in table format for input header and lines

func IPBlockFromCidrOrAddressOrIPRange

func IPBlockFromCidrOrAddressOrIPRange(ip string) (*netset.IPBlock, error)

func IPBlockShortString

func IPBlockShortString(set *netset.IPBlock) string

func IntStr added in v0.2.1

func IntStr[I Int](v I) string

func JoinCustomStrFuncSlice

func JoinCustomStrFuncSlice[S any](slice []S, f func(s S) string, separator string) string

func JoinNonEmpty

func JoinNonEmpty(slice []string, sep string) string

func JoinNonNil

func JoinNonNil[S any](ptrSlice []*S, f func(s *S) string, sep string) string

func JoinNonNilStrings

func JoinNonNilStrings(ptrSlice []*string, sep string) string

func JoinStringifiedSlice

func JoinStringifiedSlice[S HasString](slice []S, separator string) string

func LabelFromString

func LabelFromString(value string) label

func MarshalJSON

func MarshalJSON(v any) (string, error)

func NewFilteredSliceFunc

func NewFilteredSliceFunc[v any](s []v, f func(v) bool) (res []v)

func OutputGraph

func OutputGraph(g Graph, fileName string, format OutFormat) (res string, err error)

func PointerTo

func PointerTo[T any](t T) *T

PointerTo is used as shorthand to extract pointer from const value

func SafePointerDeref

func SafePointerDeref[T any](p *T) T

SafePointerDeref dereferences pointer if not nil, else returns empty object

func SliceCompact

func SliceCompact[A comparable](s []A) []A

func SliceCountFunc

func SliceCountFunc[v any](s []v, f func(v) bool) int

func SortedJoinCustomStrFuncSlice

func SortedJoinCustomStrFuncSlice[S any](slice []S, f func(s S) string, separator string) string

func SortedJoinStringifiedSlice

func SortedJoinStringifiedSlice[S HasString](slice []S, separator string) string

func StringifiedSliceToStrings

func StringifiedSliceToStrings[S HasString](slice []S) []string

func WriteToFile

func WriteToFile(file, content string) error

func WriteYamlUsingJSON

func WriteYamlUsingJSON[A any](content []A, file string) error

Types

type DotGraph

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

func NewDotGraph

func NewDotGraph(rank bool) *DotGraph

func (*DotGraph) AddEdge

func (dotGraph *DotGraph) AddEdge(src, dst node, label label)

func (*DotGraph) JSONString

func (dotGraph *DotGraph) JSONString() (string, error)

func (*DotGraph) String

func (dotGraph *DotGraph) String() string

type EdgesGraph

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

func NewEdgesGraph

func NewEdgesGraph(header string, tableHeaderComponents []string, color bool) *EdgesGraph

func (*EdgesGraph) AddEdge

func (eg *EdgesGraph) AddEdge(src, dst node, label label)

func (*EdgesGraph) JSONString

func (eg *EdgesGraph) JSONString() (string, error)

func (*EdgesGraph) String

func (eg *EdgesGraph) String() string

type Endpoints

type Endpoints string
const (
	// target endpoints for migration config values
	EndpointsVMs  Endpoints = "vms"
	EndpointsPods Endpoints = "pods"
	EndpointsBoth Endpoints = "both"
)

func (*Endpoints) Set

func (e *Endpoints) Set(v string) error

func (*Endpoints) SetDefault

func (e *Endpoints) SetDefault()

func (*Endpoints) String

func (e *Endpoints) String() string

func (*Endpoints) Type

func (e *Endpoints) Type() string

type Graph

type Graph interface {
	AddEdge(src, dst node, label label)
	String() string
	JSONString() (string, error)
}

Graph interface is implemented by: EdgesGraph (for text output) DotGraph (for dot/svg output) TreeGraph (for json output)

type HasString

type HasString interface {
	String() string
}

type Int added in v0.2.1

type Int interface {
	int | uint | int8 | uint8 | int16 | uint16 | int32 | uint32 | int64 | uint64
}

type LogLevel added in v0.2.1

type LogLevel string
const (
	LogLevelFatal  LogLevel = "fatal"
	LogLevelError  LogLevel = "error"
	LogLevelWarn   LogLevel = "warn"
	LogLevelInfo   LogLevel = "info"
	LogLevelDebug  LogLevel = "debug"
	LogLevelDebug2 LogLevel = "debug2" // more debug messages than "debug" level
)

func (*LogLevel) Set added in v0.2.1

func (e *LogLevel) Set(v string) error

func (*LogLevel) SetDefault added in v0.2.1

func (e *LogLevel) SetDefault()

func (*LogLevel) String added in v0.2.1

func (e *LogLevel) String() string

func (*LogLevel) Type added in v0.2.1

func (e *LogLevel) Type() string

type OutFormat

type OutFormat string

/////////////////////////////////////////////////////////////////////////////////////////// outFormat is a custom flag type. Cobra allows to define custom value types to be used as flags through the pflag.(*FlagSet).Var() method. defining a new type that implements the pflag.Value interface.

const (
	// out format values
	TextFormat OutFormat = "txt"
	DotFormat  OutFormat = "dot"
	JSONFormat OutFormat = "json"
	SVGFormat  OutFormat = "svg"
)

func (*OutFormat) Set

func (e *OutFormat) Set(v string) error

Set must have pointer receiver so it doesn't change the value of a copy

func (*OutFormat) SetDefault

func (e *OutFormat) SetDefault()

func (*OutFormat) String

func (e *OutFormat) String() string

String is used both by fmt.Print and by Cobra in help text

func (*OutFormat) Type

func (e *OutFormat) Type() string

Type is only used in help text

type OutputParameters

type OutputParameters struct {
	Format   OutFormat
	FileName string
	VMs      []string
	Explain  bool
	Color    bool
}

func DefaultOutputParameters

func DefaultOutputParameters() OutputParameters

type SectionsOutput added in v0.2.1

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

func (*SectionsOutput) AddSection added in v0.2.1

func (s *SectionsOutput) AddSection(section, content string)

func (*SectionsOutput) GenerateSectionsString added in v0.2.1

func (s *SectionsOutput) GenerateSectionsString() string

type Segments

type Segments string
const (
	// target options for segments migration values
	SegmentsToPodNetwork Segments = "pod-network"
	SegmentsToUDNs       Segments = "udns"
)

func (*Segments) Set

func (e *Segments) Set(v string) error

func (*Segments) SetDefault

func (e *Segments) SetDefault()

func (*Segments) String

func (e *Segments) String() string

func (*Segments) Type

func (e *Segments) Type() string

type TableOptions

type TableOptions struct {
	Colors    bool
	SortLines bool
}

type TreeGraph

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

////////////////////////////////////////////////////////////////

func NewTreeGraph

func NewTreeGraph() *TreeGraph

func (*TreeGraph) AddEdge

func (tg *TreeGraph) AddEdge(src, dst node, label label)

func (*TreeGraph) JSONString

func (tg *TreeGraph) JSONString() (string, error)

func (*TreeGraph) String

func (tg *TreeGraph) String() string

Jump to

Keyboard shortcuts

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