Documentation
¶
Overview ¶
Package common collection of small utils
Index ¶
- Variables
- func CanRead(filename string) bool
- func ChdirToFile(file string) error
- func CheckSkip(line string) (skip bool)
- func CheckType(t any, expected string) (ok bool, haveType string)
- func CmdFlagChanged(cmd *cobra.Command, name string) (changed bool)
- func CmdRun(cmd *cobra.Command, args []string) (out string, err error)
- func CommandExists(command string) bool
- func DestroyDockerContainer(container *dockertest.Resource)
- func ExecDockerCmd(container *dockertest.Resource, cmd []string) (out string, code int, err error)
- func ExecuteOsCommand(cmdArgs []string, stdIn io.Reader) (stdOut string, stdErr string, err error)
- func FileExists(filename string) bool
- func FindCommand(name string) string
- func FindFileInPath(filename string, dirs []string) string
- func FormatUnixtsString(ts string, layout string) string
- func GetBoolEnv(key string, fallback bool) bool
- func GetBoolVal(value string) (bool, error)
- func GetContainerHostAndPort(container *dockertest.Resource, portID string) (server string, port int)
- func GetDockerAPIVersion(client *docker.Client) (v string)
- func GetDockerHost(pool *dockertest.Pool) string
- func GetDockerPool() (*dockertest.Pool, error)
- func GetEnv(key, fallback string) string
- func GetFloatEnv(key string, fallback float64) float64
- func GetFloatVal(value string) (float64, error)
- func GetGitRootDir(start string) (rootDir string, err error)
- func GetGitlabJobURL() string
- func GetGitlabPipelineURL() string
- func GetHexInt64Val(value string) (int64, error)
- func GetHostPort(input string) (host string, port int, err error)
- func GetHostname() string
- func GetInt64Val(value string) (int64, error)
- func GetIntEnv(key string, fallback int) int
- func GetIntVal(value string) (int, error)
- func GetLastCommit(gitDir string, filename string) (c *object.Commit, err error)
- func GetStringEnv(key string, fallback string) string
- func GetVersionedDockerPool(version string) (pool *dockertest.Pool, err error)
- func HTTPGet(url string, timeout int) (resp string, err error)
- func InArray(needle interface{}, haystack interface{}) (exists bool, index int)
- func IsDir(name string) bool
- func IsFile(name string) bool
- func IsGitFile(filename string) (rootDir string, gitFileName string, err error)
- func IsNil(i interface{}) bool
- func IsNumeric(s string) bool
- func MergeMaps(m1, m2 interface{}) (interface{}, error)
- func PromptPassword(label string) (pw string, err error)
- func RandString(n int) string
- func ReadFileByLine(filename string) ([]string, error)
- func ReadFileToString(filename string) (string, error)
- func ReadFileToStruct(filename string, data any) (err error)
- func ReadStdinByLine() ([]string, error)
- func ReadStdinToString() (string, error)
- func RemoveSpace(s string) string
- func ReverseMap[M ~map[K]V, K comparable, V comparable](m M) map[V]K
- func SetHostPort(host string, port int) string
- func StructToJSON(m interface{}) (string, error)
- func StructToMap(obj interface{}) (map[string]interface{}, error)
- func StructToString(o interface{}, prefix string) (s string)
- func WriteStringToFile(filename string, content string) error
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultPorts is a map of default ports for common services DefaultPorts = map[string]int{ "http": 80, "https": 443, "ftp": 21, "ftps": 990, "ssh": 22, "ldap": 389, "ldaps": 636, "imap": 143, "imaps": 993, "smtp": 25, "smtps": 465, "pop3": 110, "pop3s": 995, "mysql": 3306, "postgresql": 5432, "oracle": 1521, "mssql": 1433, "mongodb": 27017, "redis": 6379, "memcached": 11211, "couchdb": 5984, "couchbase": 8091, "cassandra": 9042, "elasticsearch": 9200, "kibana": 5601, "grafana": 3000, "prometheus": 9090, "alertmanager": 9093, "consul": 8500, "vault": 8200, "nomad": 4646, "etcd": 2379, "zookeeper": 2181, "kafka": 9092, "rabbitmq": 5672, "nats": 4222, "nats-streaming": 4223, "mqtt": 1883, "coap": 5683, "dns": 53, "dhcp": 67, "tftp": 69, "ntp": 123, "snmp": 161, "syslog": 514, "radius": 1812, "radius-acct": 1813, } )
var InputReader = os.Stdin
Functions ¶
func ChdirToFile ¶
ChdirToFile change working directory to the filename
func CheckType ¶ added in v1.9.3
CheckType checks if an interface is of a certain type and returns if it matches expected or is Nil
func CmdFlagChanged ¶ added in v1.9.2
CmdFlagChanged checks if the named commandline flag has been supplied and changed
func CommandExists ¶ added in v1.13.0
CommandExists checks if a command exists in PATH
func DestroyDockerContainer ¶ added in v1.9.0
func DestroyDockerContainer(container *dockertest.Resource)
DestroyDockerContainer destroys a docker container
func ExecDockerCmd ¶ added in v1.9.0
ExecDockerCmd executes an OS cmd within container and print output
func ExecuteOsCommand ¶ added in v1.4.0
ExecuteOsCommand runs an OS command and returns output
func FileExists ¶ added in v1.9.5
FileExists checks if a file or directory exists
func FindCommand ¶ added in v1.19.0
FindCommand searches for a command in the PATH environment variable
func FindFileInPath ¶ added in v1.17.0
FindFileInPath searches for a file with the given name in the provided directories. It returns the absolute path of the found file, or an empty string if not found.
func FormatUnixtsString ¶ added in v1.11.1
FormatUnixtsString converts a unix timestamp string to a human readable
func GetBoolEnv ¶ added in v1.7.3
GetBoolEnv read an OS Env variable and convert to bool
func GetBoolVal ¶ added in v1.7.3
GetBoolVal convert String to bool
func GetContainerHostAndPort ¶ added in v1.9.0
func GetContainerHostAndPort(container *dockertest.Resource, portID string) (server string, port int)
GetContainerHostAndPort returns the mapped host and port of a docker container for a given portID
func GetDockerAPIVersion ¶ added in v1.19.0
GetDockerAPIVersion returns the running supported docker API version
func GetDockerHost ¶ added in v1.19.0
func GetDockerHost(pool *dockertest.Pool) string
GetDockerHost returns the docker host from a pool
func GetDockerPool ¶ added in v1.9.0
func GetDockerPool() (*dockertest.Pool, error)
GetDockerPool initializes a docker pool
func GetFloatEnv ¶ added in v1.7.3
GetFloatEnv read an OS Env variable and convert to float64
func GetFloatVal ¶ added in v1.7.3
GetFloatVal convert String to float64
func GetGitRootDir ¶ added in v1.9.6
GetGitRootDir returns the root directory of a git repository
func GetGitlabJobURL ¶ added in v1.16.0
func GetGitlabJobURL() string
func GetGitlabPipelineURL ¶ added in v1.16.0
func GetGitlabPipelineURL() string
func GetHexInt64Val ¶ added in v1.14.0
func GetHostPort ¶ added in v1.9.0
GetHostPort returns host and port from a string
func GetHostname ¶ added in v1.10.1
func GetHostname() string
GetHostname returns the hostname as full qualified domain name
func GetInt64Val ¶ added in v1.9.0
GetInt64Val convert String to int64
func GetLastCommit ¶ added in v1.9.6
GetLastCommit returns a string with last commit details for given file
func GetStringEnv ¶ added in v1.7.3
GetStringEnv read an OS Env variable
func GetVersionedDockerPool ¶ added in v1.19.0
func GetVersionedDockerPool(version string) (pool *dockertest.Pool, err error)
GetVersionedDockerPool returns a docker pool with a specific docker version, use running version if empty
func InArray ¶ added in v1.9.6
InArray will search element inside array with any type. Will return boolean and index for matched element. True and index more than 0 if element is exist. needle is element to search, haystack is slice of value to be search. Taken from https://github.com/SimonWaldherr/golang-examples/blob/master/advanced/in_array.go
func IsGitFile ¶ added in v1.9.6
IsGitFile returns nil if given file is part of a git repo or a meaningful message
func MergeMaps ¶ added in v1.17.0
func MergeMaps(m1, m2 interface{}) (interface{}, error)
MergeMapsAny merges two maps of any types, inserting all key-value pairs from the second map into the first map, and returns the updated map. Note: Both input maps must be of the same type.
func PromptPassword ¶ added in v1.24.0
func RandString ¶ added in v1.14.4
RandString generates a pseudo random string with letters and digits with desired length
func ReadFileByLine ¶
ReadFileByLine read a file and return array of lines
func ReadFileToString ¶
ReadFileToString read a file and return a string
func ReadFileToStruct ¶ added in v1.15.0
ReadFileToStruct reads a file or from stdin and fills a given struct
func ReadStdinByLine ¶ added in v1.14.11
ReadStdinByLine reads stdin and returns array of lines
func ReadStdinToString ¶ added in v1.14.11
ReadStdinToString reads stdin and returns a string
func RemoveSpace ¶ added in v1.4.0
RemoveSpace deletes all spaces and newlines from string
func ReverseMap ¶ added in v1.14.0
func ReverseMap[M ~map[K]V, K comparable, V comparable](m M) map[V]K
ReverseMap will reverse a map
func SetHostPort ¶ added in v1.9.0
SetHostPort returns host:port from a string host and port int
func StructToJSON ¶ added in v1.18.0
func StructToMap ¶ added in v1.14.8
StructToMap converts a struct to a map
func StructToString ¶ added in v1.14.8
StructToString converts a struct to sorted key string
func WriteStringToFile ¶ added in v1.14.4
WriteStringToFile saves a string to filename and assign rights 0600
Types ¶
This section is empty.