utils

package
v2.3.0-beta35 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package utils provides utility functions for the Keploy application.

Index

Constants

This section is empty.

Variables

View Source
var ConfigGuide = `
# Visit [https://keploy.io/docs/running-keploy/configuration-file/] to learn about using keploy through configration file.
`
View Source
var Emoji = "\U0001F430" + " Keploy:"
View Source
var ErrCode = 0
View Source
var ErrGitHubAPIUnresponsive = errors.New("GitHub API is unresponsive")
View Source
var TemplatizedValues = map[string]interface{}{}
View Source
var Version string
View Source
var VersionIdenitfier string
View Source
var WarningSign = "\U000026A0"

Functions

func AddToGitIgnore

func AddToGitIgnore(logger *zap.Logger, path string, ignoreString string) error

func AskForConfirmation

func AskForConfirmation(s string) (bool, error)

AskForConfirmation asks the user for confirmation. A user must type in "yes" or "no" and then press enter. It has fuzzy matching, so "y", "Y", "yes", "YES", and "Yes" all count as confirmations. If the input is not recognized, it will ask again. The function does not return until it gets a valid response from the user.

func BindFlagsToViper

func BindFlagsToViper(logger *zap.Logger, cmd *cobra.Command, viperKeyPrefix string) error

func CheckFileExists

func CheckFileExists(path string) bool

func DeleteFileIfNotExists

func DeleteFileIfNotExists(logger *zap.Logger, name string) (err error)

func DetectLanguage

func DetectLanguage(logger *zap.Logger, cmd string) (config.Language, string)

DetectLanguage detects the language of the test command and returns the executable

func EnsureRmBeforeName

func EnsureRmBeforeName(cmd string) string

func ExecCancel

func ExecCancel()

func ExpandPath

func ExpandPath(path string) (string, error)

ExpandPath expands a given path, replacing the tilde with the user's home directory

func FileExists

func FileExists(path string) (bool, error)

FileExists checks if a file exists and is not a directory at the given path.

func GenerateGithubActions

func GenerateGithubActions(logger *zap.Logger, appCmd string)

GenerateGithubActions generates a GitHub Actions workflow file for Keploy

func GetAbsPath

func GetAbsPath(path string) (string, error)

func GetLastDirectory

func GetLastDirectory() (string, error)

func GetPIDFromPort

func GetPIDFromPort(_ context.Context, logger *zap.Logger, port int) (uint32, error)

func HandleRecovery

func HandleRecovery(logger *zap.Logger, r interface{}, errMsg string)

HandleRecovery handles the common logic for recovering from a panic.

func Hash

func Hash(data []byte) string

func InterruptProcessTree

func InterruptProcessTree(logger *zap.Logger, ppid int, sig syscall.Signal) error

InterruptProcessTree interrupts an entire process tree using the given signal

func IsDockerCmd

func IsDockerCmd(kind CmdType) bool

func IsFileEmpty

func IsFileEmpty(filePath string) (bool, error)

func Keys

func Keys(m map[string][]string) []string

Keys returns an array containing the keys of the given map.

func LogError

func LogError(logger *zap.Logger, err error, msg string, fields ...zap.Field)

LogError logs the error with the provided fields if the error is not context.Canceled.

func NewCtx

func NewCtx() context.Context

func Recover

func Recover(logger *zap.Logger)

Recover recovers from a panic and logs the stack trace to Sentry. It also stops the global context.

func ReplaceHost

func ReplaceHost(currentURL string, ipAddress string) (string, error)

func ReplacePort

func ReplacePort(currentURL string, port string) (string, error)

func RestoreUmask

func RestoreUmask(oldMask int)

func SendSignal

func SendSignal(logger *zap.Logger, pid int, sig syscall.Signal) error

func SentryInit

func SentryInit(logger *zap.Logger, dsn string)

func SetCancel

func SetCancel(c context.CancelFunc)

func SetCoveragePath

func SetCoveragePath(logger *zap.Logger, goCovPath string) (string, error)

SetCoveragePath takes a goCovPath and sets the coverage path accordingly. It returns an error if the path is a file or if the path does not exist.

func SetUmask

func SetUmask() int

func Stop

func Stop(logger *zap.Logger, reason string) error

Stop requires a reason to stop the server. this is to ensure that the server is not stopped accidentally. and to trace back the stopper

func ToAbsPath

func ToAbsPath(logger *zap.Logger, originalPath string) string

func ToFloat

func ToFloat(value interface{}) float64

func ToInt

func ToInt(value interface{}) int

func ToString

func ToString(value interface{}) string

Types

type AutoInc

type AutoInc struct {
	sync.Mutex // ensures autoInc is goroutine-safe
	// contains filtered or unexported fields
}

func (*AutoInc) Next

func (a *AutoInc) Next() (id int)

type CmdError

type CmdError struct {
	Type ErrType
	Err  error
}

func ExecuteCommand

func ExecuteCommand(ctx context.Context, logger *zap.Logger, userCmd string, cancel func(cmd *exec.Cmd) func() error, waitDelay time.Duration) CmdError

type CmdType

type CmdType string
const (
	DockerRun     CmdType = "docker-run"
	DockerStart   CmdType = "docker-start"
	DockerCompose CmdType = "docker-compose"
	Native        CmdType = "native"
	Empty         CmdType = ""
)

CmdType constants

func FindDockerCmd

func FindDockerCmd(cmd string) CmdType

FindDockerCmd checks if the cli is related to docker or not, it also returns if it is a docker compose file

type ErrType

type ErrType string
const (
	Init    ErrType = "init"
	Runtime ErrType = "runtime"
)

ErrType constants to get the type of error, during init or runtime

type GitHubRelease

type GitHubRelease struct {
	TagName string `json:"tag_name"`
	Body    string `json:"body"`
}

func GetLatestGitHubRelease

func GetLatestGitHubRelease(ctx context.Context, logger *zap.Logger) (GitHubRelease, error)

GetLatestGitHubRelease fetches the latest version and release body from GitHub releases with a timeout.

Directories

Path Synopsis
Package log provides utility functions for logging.
Package log provides utility functions for logging.

Jump to

Keyboard shortcuts

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