Documentation
¶
Overview ¶
Package utils provides utility functions for the Keploy application.
Index ¶
- Variables
- func AddToGitIgnore(logger *zap.Logger, path string, ignoreString string) error
- func AskForConfirmation(ctx context.Context, s string) (bool, error)
- func BindFlagsToViper(logger *zap.Logger, cmd *cobra.Command, viperKeyPrefix string) error
- func CheckFileExists(path string) bool
- func DeleteFileIfNotExists(logger *zap.Logger, name string) (err error)
- func DetectLanguage(logger *zap.Logger, cmd string) (config.Language, string)
- func EnsureRmBeforeName(cmd string) string
- func ExecCancel()
- func ExpandPath(path string) (string, error)
- func FileExists(path string) (bool, error)
- func GenerateGithubActions(logger *zap.Logger, appCmd string)
- func GetAbsPath(path string) (string, error)
- func GetLastDirectory() (string, error)
- func GetPIDFromPort(_ context.Context, logger *zap.Logger, port int) (uint32, error)
- func GetReqMeta(req *http.Request) map[string]string
- func GetVersionAsComment() string
- func HandleRecovery(logger *zap.Logger, r interface{}, errMsg string)
- func Hash(data []byte) string
- func InterruptProcessTree(logger *zap.Logger, ppid int, sig syscall.Signal) error
- func IsDockerCmd(kind CmdType) bool
- func IsFileEmpty(filePath string) (bool, error)
- func IsPassThrough(logger *zap.Logger, req *http.Request, destPort uint, ...) bool
- func IsXMLResponse(resp *models.HTTPResp) bool
- func Keys(m map[string][]string) []string
- func LogError(logger *zap.Logger, err error, msg string, fields ...zap.Field)
- func NewCtx() context.Context
- func ParseMetadata(metadataStr string) (map[string]interface{}, error)
- func Recover(logger *zap.Logger)
- func RemoveDoubleQuotes(tempMap map[string]interface{})
- func ReplaceBaseURL(currentURL string, baseURL string) (string, error)
- func ReplaceGrpcHost(authority string, ipAddress string) (string, error)
- func ReplaceGrpcPort(authority string, port string) (string, error)
- func ReplaceHost(currentURL string, ipAddress string) (string, error)
- func ReplacePort(currentURL string, port string) (string, error)
- func RestoreUmask(oldMask int)
- func SendSignal(logger *zap.Logger, pid int, sig syscall.Signal) error
- func SentryInit(logger *zap.Logger, dsn string)
- func SetCancel(c context.CancelFunc)
- func SetCoveragePath(logger *zap.Logger, goCovPath string) (string, error)
- func SetUmask() int
- func Stop(logger *zap.Logger, reason string) error
- func ToAbsPath(logger *zap.Logger, originalPath string) string
- func ToFloat(value interface{}) float64
- func ToInt(value interface{}) int
- func ToString(val interface{}) string
- func TrimSpaces(input string) string
- type AutoInc
- type CmdError
- type CmdType
- type ErrType
- type GitHubRelease
Constants ¶
This section is empty.
Variables ¶
var ConfigGuide = `` /* 133-byte string literal not displayed */
var Emoji = "\U0001F430" + " Keploy:"
var ErrCode = 0
var SecretValues = map[string]interface{}{}
var TemplatizedValues = map[string]interface{}{}
var Version string
var VersionIdenitfier string
var WarningSign = "\U000026A0"
Functions ¶
func AddToGitIgnore ¶
func AskForConfirmation ¶
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 or interrupted, exit gracefully as "no".
func BindFlagsToViper ¶
func DeleteFileIfNotExists ¶
func DetectLanguage ¶
DetectLanguage detects the language of the test command and returns the executable
func ExecCancel ¶
func ExecCancel()
func ExpandPath ¶
ExpandPath expands a given path, replacing the tilde with the user's home directory
func FileExists ¶
FileExists checks if a file exists and is not a directory at the given path.
func GenerateGithubActions ¶
GenerateGithubActions generates a GitHub Actions workflow file for Keploy
func GetPIDFromPort ¶
func GetReqMeta ¶
GetReqMeta returns the metadata of the request
func HandleRecovery ¶
HandleRecovery handles the common logic for recovering from a panic.
func InterruptProcessTree ¶
InterruptProcessTree interrupts an entire process tree using the given signal
func IsPassThrough ¶
func Keys ¶
Keys returns an array containing the keys of the given map.
func LogError ¶
LogError logs the error with the provided fields if the error is not context.Canceled.
func Recover ¶
Recover recovers from a panic and logs the stack trace to Sentry. It also stops the global context.
func RemoveDoubleQuotes ¶
func RemoveDoubleQuotes(tempMap map[string]interface{})
RemoveDoubleQuotes removes all double quotes from the values in the provided template map. This function handles cases where the templating engine fails to parse values containing both single and double quotes. For example: Input: '"Not/A)Brand";v="8", "Chromium";v="126", "Brave";v="126"' Output: Not/A)Brand;v=8, Chromium;v=126, Brave;v=126
func ReplaceBaseURL ¶
ReplaceBaseURL replaces the base URL (scheme + host) of the given URL with the provided baseURL. It returns the updated URL as a string or an error if the operation fails.
func SetCancel ¶
func SetCancel(c context.CancelFunc)
func SetCoveragePath ¶
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 Stop ¶
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
Types ¶
type AutoInc ¶
type CmdError ¶
type CmdType ¶
type CmdType string
type GitHubRelease ¶
Source Files
¶
- ctx.go
- inc.go
- mask_others.go
- signal_others.go
- utils.go