helper

package
v0.0.0-...-52cd4e6 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const BackendNameMaxLength = 63
View Source
const BackendNameUidMaxLength = 5
View Source
const Indentation = `  `

Variables

This section is empty.

Functions

func AppendUid

func AppendUid(name string, uidLen int) string

AppendUid append uid after the name

func BackendAlreadyExistsError

func BackendAlreadyExistsError(backend string, filePath string) error

BackendAlreadyExistsError return a backend already exists error

func BackendNameMapping

func BackendNameMapping(name string) string

BackendNameMapping mapping backend name

func BashExecReturnStdOut

func BashExecReturnStdOut(ctx context.Context, cli string, args []string) ([]byte, error)

BashExecReturnStdOut used to exec command, and return stdout.

func BuildBackendName

func BuildBackendName(name string) string

BuildBackendName build backend name

func ConvertInterface

func ConvertInterface(i interface{}) interface{}

ConvertInterface convert interface

func Examples

func Examples(s string) string

Examples normalizes a command's examples to follow the conventions.

func ExecReturnStdOut

func ExecReturnStdOut(cli string, args []string) ([]byte, error)

ExecReturnStdOut used to exec command, and return stdout.

func ExecWithStdin

func ExecWithStdin(cli string, data []byte, args []string) error

ExecWithStdin used to exec command, enter parameters using stdin

func GenerateHashCode

func GenerateHashCode(txt string, max int) string

GenerateHashCode generate hash code

func GetBackendName

func GetBackendName(name string) string

func GetPrintFunc

func GetPrintFunc[T any](format string) func(t []T)

GetPrintFunc get print function by format type

func GetSelectedNumber

func GetSelectedNumber(tips string, maxValue int) (int, error)

GetSelectedNumber get the number entered by the user

func IsDNSFormat

func IsDNSFormat(source string) bool

IsDNSFormat Determine if the DNS format is met

func JSONToYAML

func JSONToYAML(j []byte) ([]byte, error)

JSONToYAML Converts JSON to YAML.

func LogErrorf

func LogErrorf(format string, err error) error

LogErrorf write error log and return the error

func LogInfof

func LogInfof(ctx context.Context, format string, args ...interface{})

LogInfof write message

func LogWarningf

func LogWarningf(ctx context.Context, format string, err error) error

LogWarningf write error log and return the error

func MapTo

func MapTo[I any, O any](list []I, consumer func(I) O) []O

MapTo Returns an array consisting of the results of applying the given function to the elements of this list.

func PrintBackend

func PrintBackend[T any](t []T, notFound []string, printFunc func(t []T))

PrintBackend print backend

func PrintBackendAlreadyExists

func PrintBackendAlreadyExists(backend string)

PrintBackendAlreadyExists print backend already exists error

func PrintNoResourceBackend

func PrintNoResourceBackend(namespace string)

PrintNoResourceBackend print not found backend

func PrintNoResourceCert

func PrintNoResourceCert(backend, namespace string)

PrintNoResourceCert print no cert found

func PrintNotFoundBackend

func PrintNotFoundBackend(names ...string)

PrintNotFoundBackend print not found backend

func PrintNotFoundSecret

func PrintNotFoundSecret(names ...string)

PrintNotFoundSecret print not found secret

func PrintOperateResult

func PrintOperateResult(resourceType, operate string, resourceNames ...string)

PrintOperateResult used to print operate result to terminal e.g. backend/backend-name created

func PrintResult

func PrintResult(out string)

PrintResult used to print result to terminal

func PrintSecret

func PrintSecret[T any](t []T, notFound []string, printFunc func(t []T))

PrintSecret print secret

func PrintWithJson

func PrintWithJson[T any](data []T)

PrintWithJson print json

func PrintWithTable

func PrintWithTable[T any](data []T)

PrintWithTable print table

func PrintWithYaml

func PrintWithYaml[T any](data []T)

PrintWithYaml print yaml

func PrintlnError

func PrintlnError(err error) error

PrintlnError used to print error to terminal

func ReadHeader

func ReadHeader[T any](t T) []string

ReadHeader read struct tag name T is a struct

func ReadRow

func ReadRow[T any](t T) []string

ReadRow read struct filed value T is a struct

func ReadStruct

func ReadStruct[T any, O any](t T, readFunc func(field reflect.StructField, value reflect.Value) (O, bool)) []O

ReadStruct read struct T is a struct readFunc is a read struct func, e.g. read struct filed value

func StartStdInput

func StartStdInput() (string, string, error)

StartStdInput start stdin process

func StructToYAML

func StructToYAML[T any](t T) ([]byte, error)

StructToYAML convert struct to yaml

Types

type GlobalGoroutineLimit

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

GlobalGoroutineLimit is used to limit concurrency of goroutine

func NewGlobalGoroutineLimit

func NewGlobalGoroutineLimit(maxGoroutineNum int) *GlobalGoroutineLimit

NewGlobalGoroutineLimit initialize a GlobalGoroutineLimit instance

func (*GlobalGoroutineLimit) AddWork

func (n *GlobalGoroutineLimit) AddWork(num int)

AddWork add the work num for wait

func (*GlobalGoroutineLimit) HandleWork

func (n *GlobalGoroutineLimit) HandleWork(work func())

HandleWork handle the work func with limit

func (*GlobalGoroutineLimit) Wait

func (n *GlobalGoroutineLimit) Wait()

Wait wait all works done

type Normalizer

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

func NewNormalizer

func NewNormalizer(s string) Normalizer

NewNormalizer initialize an instance of Normalizer

type Once

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

Once same as sync.Once, but the Do() method is overridden.

func (*Once) Do

func (o *Once) Do(f func() error)

Do same as sync.Once.Do(), but you can determine whether the execution is successful by returning error.

type Task

type Task interface {
	Do()
}

Task Define interfaces required by asynchronous tasks.

type TaskHandler

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

TaskHandler Define asynchronous task processing configuration

func NewTransmitter

func NewTransmitter(maxHandlerNum, taskCapacity int) *TaskHandler

NewTransmitter initialize a TaskHandler instance

func (*TaskHandler) AddTask

func (t *TaskHandler) AddTask(task Task)

AddTask add an asynchronous Task

func (*TaskHandler) End

func (t *TaskHandler) End()

End the adding task.

func (*TaskHandler) Start

func (t *TaskHandler) Start()

Start Create maxHandlerLimit goroutines to execute the task.

func (*TaskHandler) Wait

func (t *TaskHandler) Wait()

Wait for all tasks to complete

Jump to

Keyboard shortcuts

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