utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileExists

func FileExists(filename string) bool

FileExists checks if a file exists and is not a directory before we try using it to prevent further errors.

func FolderExists

func FolderExists(filename string) bool

FolderExists checks if a file exists and is not a directory before we try using it to prevent further errors.

func GetCurrentExecPath

func GetCurrentExecPath() string

GetCurrentExecPath returns the path of the executable file

func GetParams

func GetParams(regEx, str string) (paramsMap map[string]string)

GetParams returns a dictionary of group name and group value in a given regex defined by a string

func GetParamsWithRegex

func GetParamsWithRegex(compRegEx *regexp.Regexp, str string) (paramsMap map[string]string)

GetParamsWithRegex returns a dictionary of group name and group value in a given regex

Types

type HttpClientInterface

type HttpClientInterface interface {
	SendRequest(
		url string,
		cookieJar *cookiejar.Jar,
		header map[string]string,
		method string,
		payload io.Reader,
		queryParams map[string]string,
		skipInsecureVerify bool,
		username string,
		password string,
		timeout time.Duration,
	) (content string, statusCode int, err error)
}

HttpClientInterface is a simple interface that defines the functions of a HTTP client

type IK8sClientHelper

type IK8sClientHelper interface {
	GetClient(pathToCfg string) (*K8sClient, error)
	GetClientAndConfig(pathToCfg string) (*K8sClient, *rest.Config, error)
}

IK8sClientHelper is the interface to get a Client Using this way, we can easily create a mock object that satisfies this interface

type K8sClient

type K8sClient struct {
	Clientset kubernetes.Interface
}

K8sClient is the wrapper of Kubernetes K8sClient that helps us easier to mock and test using Dependency Injection

type K8sClientHelper

type K8sClientHelper struct {
}

ClienHelper is a helper class that implement IClientHelper, and returns the real Kubernetes Clientset

func (K8sClientHelper) GetClient

func (c K8sClientHelper) GetClient(pathToCfg string) (*K8sClient, error)

GetClient returns a Kubernetes Clientset which is built from a given config file path, for example `~/.kube/config` if the file path is empty, we will use the mode "InCluster" (with a token of serviec account stored in `/var/run/secrets/kubernetes.io/serviceaccount/token`) otherwise, use the server information and authentication information from the path

func (K8sClientHelper) GetClientAndConfig

func (c K8sClientHelper) GetClientAndConfig(pathToCfg string) (*K8sClient, *rest.Config, error)

GetClientAndConfig returns a Kubernetes Clientset and the REST configuration which is built from a given config file path, for example `~/.kube/config` if the file path is empty, we will use the mode "InCluster" (with a token of serviec account stored in `/var/run/secrets/kubernetes.io/serviceaccount/token`) otherwise, use the server information and authentication information from the path

type RealHTTPClient

type RealHTTPClient struct {
}

RealHTTPClient implements the real http client service

func (RealHTTPClient) SendRequest

func (RealHTTPClient) SendRequest(
	url string,
	cookieJar *cookiejar.Jar,
	header map[string]string,
	method string,
	payload io.Reader,
	queryParams map[string]string,
	skipInsecureVerify bool,
	username string,
	password string,
	timeout time.Duration,
) (content string, statusCode int, err error)

SendRequest sends a get request and return the response if the response is compressed, un-compress it first and then return

Jump to

Keyboard shortcuts

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