Documentation
¶
Index ¶
- func Closers() closerS
- func ColoredTty(w io.Writer) bool
- func DebugBuild() bool
- func DebugMode() bool
- func DebuggerAttached() bool
- func DockerBuild() bool
- func Env() states.CmdrMinimal
- func FileExists(filepath string) bool
- func GetDebugLevel() int
- func GetNoColorLevel() int
- func GetQuietLevel() int
- func GetTraceLevel() int
- func GetTtySize() (cols, rows int)
- func GetVerboseLevel() int
- func InDebugMode() bool
- func InDebugging() bool
- func InDevelopingTime() (status bool)
- func InDocker() bool
- func InDockerEnvSimple() (status bool)
- func InIstio() bool
- func InK8s() bool
- func InK8sYN() bool
- func InTesting() bool
- func InTestingT(args []string) bool
- func InTracing() bool
- func InVscodeTerminal() bool
- func IstioBuild() bool
- func K8sBuild() bool
- func NoColorMode() bool
- func QuietModeEnabled() bool
- func ReadFile(filename string) ([]byte, error)
- func ReadPassword() (text string, err error)
- func SetDebugLevel(hits int)
- func SetDebugMode(b bool)
- func SetNoColorLevel(hits int)
- func SetNoColorMode(b bool)
- func SetQuietLevel(hits int)
- func SetQuietMode(b bool)
- func SetTraceLevel(hits int)
- func SetTraceMode(b bool)
- func SetVerboseLevel(hits int)
- func SetVerboseMode(b bool)
- func Signals() signalS
- func States() states.CmdrMinimal
- func StripEscapes(str string) (strCleaned string)
- func TraceMode() bool
- func Tracing() bool
- func Tty(w io.Writer) bool
- func TtyEscaped(s string) bool
- func UpdateEnvWith(env states.CmdrMinimal)
- func VerboseBuild() bool
- func VerboseModeEnabled() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColoredTty ¶ added in v0.5.1
ColoredTty detects a writer if it is a colorful tty device.
A colorful tty device can receive ANSI escaped sequences and draw its.
func DebugBuild ¶
func DebugBuild() bool
func DebuggerAttached ¶
func DebuggerAttached() bool
DebuggerAttached returns status if debugger attached or is a debug build.
See also InDebugging.
To check wildly like cli app debug mode (via --debug), call InDebugMode ¶
To find parent process is dlv (that is, detecting a real debugger present), another library needed.
func DockerBuild ¶
func DockerBuild() bool
func Env ¶
func Env() states.CmdrMinimal
func FileExists ¶ added in v0.5.7
FileExists detects if a file or a directory is existed.
func GetDebugLevel ¶
func GetDebugLevel() int
func GetNoColorLevel ¶
func GetNoColorLevel() int
func GetQuietLevel ¶
func GetQuietLevel() int
func GetTraceLevel ¶
func GetTraceLevel() int
func GetTtySize ¶
func GetTtySize() (cols, rows int)
GetTtySize returns the window size in columns and rows in the active console window. The return value of this function is in the order of cols, rows.
func GetVerboseLevel ¶
func GetVerboseLevel() int
func InDebugMode ¶
func InDebugMode() bool
InDebugMode returns if:
- debugger attached
- a debug build
- SetDebugMode(true) called.
To find parent process is dlv (that is, detecting a real debugger present), another library needed.
func InDebugging ¶
func InDebugging() bool
InDebugging returns status if debugger attached or is a debug build.
To enable the debugger attached mode for cmdr, run `go build` with `-tags=delve` options. eg:
go run -tags=delve ./cli go build -tags=delve -o my-app ./cli
For Goland, you can enable this under 'Run/Debug Configurations', by adding the following into 'Go tool arguments:'
-tags=delve
InDebugging() is a synonym to DebuggerAttached().
NOTE that `isdelve` algor is from https://stackoverflow.com/questions/47879070/how-can-i-see-if-the-goland-debugger-is-running-in-the-program
To check wildly like cli app debug mode (via --debug), call InDebugMode.
To find parent process is dlv (that is, detecting a real debugger present), another library needed.
func InDevelopingTime ¶
func InDevelopingTime() (status bool)
InDevelopingTime detects whether is in developing time (debugging or testing).
If the main program has been built as an executable binary, we would assume which is not in developing time.
If GetDebugMode() is true, that's in developing time too.
func InDocker ¶
func InDocker() bool
InDocker detects if the service is running under docker environment.
We tests these two conditions:
- find if `/.dockerenv` exists or not.
- `docker` in buildtags
func InDockerEnvSimple ¶
func InDockerEnvSimple() (status bool)
InDockerEnvSimple detects whether is running within docker container environment.
InDockerEnvSimple finds if `/.dockerenv` exists or not.
func InIstio ¶
func InIstio() bool
InIstio detects if the service is running under istio injected.
### IMPORTANT
To make this detector work properly, you must mount a DownwordAPI volume to your container/pod. See also:
func InTestingT ¶
InTestingT detects whether is running under 'go test' mode
func InTracing ¶
func InTracing() bool
InTracing tests if trace.IsEnabled() or env.traceMode (cli app trace mode via --trace).
See the github.com/is/states/trace package.
func InVscodeTerminal ¶
func InVscodeTerminal() bool
InVscodeTerminal tests if running under visual studio code integrated terminal
func IstioBuild ¶
func IstioBuild() bool
func NoColorMode ¶
func NoColorMode() bool
func QuietModeEnabled ¶
func QuietModeEnabled() bool
func ReadPassword ¶
ReadPassword reads the password from stdin with safe protection
func SetDebugLevel ¶
func SetDebugLevel(hits int)
func SetDebugMode ¶
func SetDebugMode(b bool)
func SetNoColorLevel ¶
func SetNoColorLevel(hits int)
func SetNoColorMode ¶
func SetNoColorMode(b bool)
func SetQuietLevel ¶
func SetQuietLevel(hits int)
func SetQuietMode ¶
func SetQuietMode(b bool)
func SetTraceLevel ¶
func SetTraceLevel(hits int)
func SetTraceMode ¶
func SetTraceMode(b bool)
func SetVerboseLevel ¶
func SetVerboseLevel(hits int)
func SetVerboseMode ¶
func SetVerboseMode(b bool)
func Signals ¶ added in v0.5.7
func Signals() signalS
Signals return a signals helper so that you can catch them, raise them.
For example:
package main
import (
"context"
"fmt"
"os"
"sync"
"github.com/hedzr/env"
"github.com/hedzr/go-socketlib/net"
logz "github.com/hedzr/logg/slog"
)
func main() {
logz.SetLevel(logz.DebugLevel)
server := net.NewServer(":7099")
defer server.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
catcher := env.Signals().Catch()
catcher.WithVerboseFn(func(msg string, args ...any) {
logz.Debug(fmt.Sprintf("[verbose] %s", fmt.Sprintf(msg, args...)))
}).WithSignalCaught(func(sig os.Signal, wg *sync.WaitGroup) {
println()
logz.Debug("signal caught", "sig", sig)
if err := server.Shutdown(); err != nil {
logz.Error("server shutdown error", "err", err)
}
cancel()
}).Wait(func(stopChan chan<- os.Signal, wgShutdown *sync.WaitGroup) {
logz.Debug("entering looper's loop...")
server.WithOnShutdown(func(err error) { wgShutdown.Done() })
err := server.StartAndServe(ctx)
if err != nil {
logz.Fatal("server serve failed", "err", err)
}
})
}
func States ¶
func States() states.CmdrMinimal
States or Env returns a minimal environment settings for a typical CLI app.
See also states.CmdrMinimal.
func StripEscapes ¶
StripEscapes removes any ansi color escaped sequences from a string
func Tty ¶ added in v0.5.1
Tty detects a writer if it is abstracting from a tty (console, terminal) device.
func TtyEscaped ¶ added in v0.5.1
TtyEscaped detects a string if it contains ansi color escaped sequences
func UpdateEnvWith ¶
func UpdateEnvWith(env states.CmdrMinimal)
func VerboseBuild ¶
func VerboseBuild() bool
func VerboseModeEnabled ¶
func VerboseModeEnabled() bool
Types ¶
This section is empty.

