utils

package
v0.0.0-...-035f276 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NilArgumentError              = errors.New("NilArgumentError")
	ReadFromClosedChannelError    = errors.New("ReadFromClosedChannelError")
	CantConvertChannelDataWrapper = errors.New("Cant Convert Channel Data Wrapper to the designated type")
	SetKeyInCacheWithNoExpiration = errors.New("SetKeyInCacheWithNoExpiration")
	TimeOutError                  = errors.New("TimeOutError")
	InvalidConfiguration          = errors.New("InvalidConfiguration")
)

Functions

func AreAllKeysOfFirstMapExistsInSecondMap

func AreAllKeysOfFirstMapExistsInSecondMap(map1 map[string]interface{}, map2 map[string]interface{}) bool

AreAllKeysOfFirstMapExistsInSecondMap checks if all the keys of the first map are exist in the second map - check also nested maps.

func AreMapsHaveTheSameKeys

func AreMapsHaveTheSameKeys(map1 map[string]interface{}, map2 map[string]interface{}) bool

AreMapsHaveTheSameKeys checks if two maps have the same keys - check also nested maps.

func CheckIfAllKeysOfFirstAreInSecond

func CheckIfAllKeysOfFirstAreInSecond(path1 string, path2 string) (bool, error)

CheckIfAllKeysOfFirstAreInSecond checks if all keys of the first yaml file are exists in second yaml

func CheckIfTwoYamlsHaveTheSameKeys

func CheckIfTwoYamlsHaveTheSameKeys(path1 string, path2 string) (bool, error)

CheckIfTwoYamlsHaveTheSameKeys Checks if 2 yaml's files have the same keys. returns ...

func CreateMapFromPathOfYaml

func CreateMapFromPathOfYaml(path string) (map[string]interface{}, error)

CreateMapFromPathOfYaml Loads map from path of yaml file.

func CreateTlsConfig

func CreateTlsConfig(tlsCrtPath string, tlsKeyPath string, caCertPath string, host string) (*tls.Config, error)

CreateTlsConfig creates tls.config object.

func ExtractImagesFromPodSpec

func ExtractImagesFromPodSpec(podSpec *corev1.PodSpec) []string

ExtractImagesFromPodSpec gets pod spec and returns all images used by the pod.

func GetDeploymentInstance

func GetDeploymentInstance() *deployment

GetDeploymentInstance returns the singleton instance of deployment. in case that the deployment is not initialized, returns nil.

func GetHours

func GetHours(durationInHours int) time.Duration

GetHours receive durationInHours as int and return it as time.Duration in hours.

func GetMilliseconds

func GetMilliseconds(durationInMilliseconds int) time.Duration

GetMilliseconds receive durationInMilliseconds as int and return it as time.Duration in milliseconds.

func GetMinutes

func GetMinutes(durationInMinutes int) time.Duration

GetMinutes receive durationInMinutes as int and return it as time.Duration in minutes.

func GetPasswordFromFile

func GetPasswordFromFile(passwordPath string) (string, error)

GetPasswordFromFile gets a password from a file containing only the password TODO - change to get password directly from the secret (no mount)

func GetSeconds

func GetSeconds(durationInSeconds int) time.Duration

GetSeconds receive durationInSeconds as int and return it as time.Duration in seconds.

func GetSizeInBytes

func GetSizeInBytes(value string) int

GetSizeInBytes returns the size of value in bytes.

func GetType

func GetType(object interface{}) string

GetType returns the full type of the object. it contains the type of the object with the packages as prefixes. e.g. x: = main.User{} -- GetTypeWithoutPackage(x) -> main.User

func GetTypeWithoutPackage

func GetTypeWithoutPackage(object interface{}) string

GetTypeWithoutPackage returns the type of the object without the package that the object belongs to. e.g. x: = main.User{} -- GetTypeWithoutPackage(x) -> User

func GoToDestNode

func GoToDestNode(yamlFile *yaml1.RNode, path ...string) (destNode *yaml1.RNode, err error)

GoToDestNode returns the *Rnode of the given path.

func IsErrorIsTypeOf

func IsErrorIsTypeOf(err error, t interface{}) bool

IsErrorIsTypeOf gets an error and type of interface and returns true or false if the error caused by some error of type t. NOTICE - you should pass t as double pointer - e.g. err := &os.PathError{} err2 := &os.PathError{} IsErrorIsTypeOf(err, &err2)

func NewDeployment

func NewDeployment(configuration *DeploymentConfiguration) (*deployment, error)

NewDeployment creates new deployment in case of singleton is not initialized yet. returns error when there is already initialized instance.

func RepeatEveryTick

func RepeatEveryTick(duration time.Duration, f func() error)

RepeatEveryTick calls a given function repeatedly every duration.

func StringInSlice

func StringInSlice(str string, list []string) bool

StringInSlice return true if list contain str,false otherwise.

func UpdateDeploymentForTests

func UpdateDeploymentForTests(configuration *DeploymentConfiguration)

UpdateDeploymentForTests is used for update the singleton for tests purpose. ------ Shouldn't be used in production code ---------------

func ValidatePositiveInt

func ValidatePositiveInt(positiveIntValidationObjects ...*PositiveIntValidationObject) (bool, string)

ValidatePositiveInt gets an unknown number of variables of type int and return an false in case at least one of them is non-positive Otherwise return true

Types

type ChannelDataWrapper

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

ChannelDataWrapper is a struct that hold 2 members: data and error. Its main purpose is to enable sending and receiving generic data throw channels.

func NewChannelDataWrapper

func NewChannelDataWrapper(data interface{}, err error) *ChannelDataWrapper

NewChannelDataWrapper - NewChannelDataWrapper Ctor

func (*ChannelDataWrapper) GetData

func (wrapper *ChannelDataWrapper) GetData() (interface{}, error)

GetData gets the data from the ChannelDataWrapper. returns error (that is not nil) in case that wrapper got non-nil err in the constructor or in case that the data is nil

type DeploymentConfiguration

type DeploymentConfiguration struct {
	// IsLocalDevelopment is boolean that indicate if we are in local development or not.
	IsLocalDevelopment bool
	// Namespace  is the Namespace where the server is running
	Namespace string
}

DeploymentConfiguration is deployment configuration

type PositiveIntValidationObject

type PositiveIntValidationObject struct {
	VariableName string
	Variable     int
}

type TimeoutConfiguration

type TimeoutConfiguration struct {
	TimeDurationInMS int
}

func (*TimeoutConfiguration) ParseTimeoutConfigurationToDuration

func (configuration *TimeoutConfiguration) ParseTimeoutConfigurationToDuration() time.Duration

ParseTimeoutConfigurationToDuration gets TimeoutConfiguration parse the timeDurationInMS of TimeoutConfiguration and returns it as duration.

Jump to

Keyboard shortcuts

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