Documentation ¶
Index ¶
- Constants
- func BuildDebugStrFromHTTPRequest(req *http.Request, includeHeaders []string) ([]string, error)
- func BuildDebugStrFromHTTPResponse(resp *http.Response, includeHeaders []string) ([]string, error)
- func BuildDebugStrFromInputModel(model any) (string, error)
- func BuildDebugStrFromMap(inputMap map[string]any) string
- func BuildDebugStrFromSlice(inputSlice []string) string
- func RequestResponseCapturer(p *Printer, includeHeaders []string) config.Middleware
- type Level
- type Printer
- func (p *Printer) Debug(level Level, msg string, args ...any)
- func (p *Printer) Error(msg string, args ...any)
- func (p *Printer) Info(msg string, args ...any)
- func (p *Printer) IsVerbosityDebug() bool
- func (p *Printer) IsVerbosityError() bool
- func (p *Printer) IsVerbosityInfo() bool
- func (p *Printer) IsVerbosityWarning() bool
- func (p *Printer) Outputf(msg string, args ...any)
- func (p *Printer) Outputln(msg string)
- func (p *Printer) PagerDisplay(content string) error
- func (p *Printer) PromptForConfirmation(prompt string) error
- func (p *Printer) PromptForEnter(prompt string) error
- func (p *Printer) PromptForPassword(prompt string) (string, error)
- func (p *Printer) Warn(msg string, args ...any)
Constants ¶
const ( DebugLevel Level = "debug" InfoLevel Level = "info" WarningLevel Level = "warning" ErrorLevel Level = "error" JSONOutputFormat = "json" PrettyOutputFormat = "pretty" NoneOutputFormat = "none" )
Variables ¶
This section is empty.
Functions ¶
func BuildDebugStrFromHTTPRequest ¶ added in v0.4.0
BuildDebugStrFromHTTPRequest converts an HTTP request to a user-friendly string representation. This function also receives a list of headers to include in the output, if empty, the default headers are used. The return value is a list of strings that should be printed separately.
func BuildDebugStrFromHTTPResponse ¶ added in v0.4.0
BuildDebugStrFromHTTPResponse converts an HTTP response to a user-friendly string representation. This function also receives a list of headers to include in the output, if empty, the default headers are used. The return value is a list of strings that should be printed separately.
func BuildDebugStrFromInputModel ¶ added in v0.4.0
BuildDebugStrFromInputModel converts an input model to a user-friendly string representation. This function converts the input model to a map, removes empty values, and generates a string representation of the map. The purpose of this function is to provide a more readable output than the default JSON representation. It is particularly useful when outputting to the slog logger, as the JSON format with escaped quotes does not look good.
func BuildDebugStrFromMap ¶ added in v0.4.0
BuildDebugStrFromMap converts a map to a user-friendly string representation. This function removes empty values and generates a string representation of the map. The string representation is in the format: [key1: value1, key2: value2, ...] The keys are ordered alphabetically to make the output deterministic.
func BuildDebugStrFromSlice ¶ added in v0.4.0
BuildDebugStrFromSlice converts a slice to a user-friendly string representation.
func RequestResponseCapturer ¶ added in v0.4.0
func RequestResponseCapturer(p *Printer, includeHeaders []string) config.Middleware
RequestResponseCapturer is a middleware that captures the request and response of an HTTP request. Receives a printer and a list of headers to include in the output If the list of headers is empty, the default headers are used. The printer is used to print the captured data.
Types ¶
type Printer ¶
func NewPrinter ¶
func NewPrinter() *Printer
Creates a new printer, including setting up the default logger.
func (*Printer) Debug ¶
Print a Debug level log through the "slog" package. If the verbosity level is not Debug, it does nothing
func (*Printer) Error ¶
Print an Error level output to the defined Err output (falling back to Stderr if not set).
func (*Printer) Info ¶
Print an Info level output to the defined Err output (falling back to Stderr if not set). If the verbosity level is not Debug or Info, it does nothing.
func (*Printer) IsVerbosityDebug ¶ added in v0.4.0
Returns True if the verbosity level is set to Debug, False otherwise.
func (*Printer) IsVerbosityError ¶ added in v0.4.0
Returns True if the verbosity level is set to Error, False otherwise.
func (*Printer) IsVerbosityInfo ¶ added in v0.4.0
Returns True if the verbosity level is set to Info, False otherwise.
func (*Printer) IsVerbosityWarning ¶ added in v0.4.0
Returns True if the verbosity level is set to Warning, False otherwise.
func (*Printer) Outputf ¶
Print an output using Printf to the defined output (falling back to Stderr if not set). If output format is set to none, it does nothing
func (*Printer) Outputln ¶
Print an output using Println to the defined output (falling back to Stderr if not set). If output format is set to none, it does nothing
func (*Printer) PagerDisplay ¶ added in v0.2.3
Shows the content in the command's stdout using the "less" command If output format is set to none, it does nothing
func (*Printer) PromptForConfirmation ¶
Prompts the user for confirmation.
Returns nil only if the user (explicitly) answers positive. Returns ErrAborted if the user answers negative.
func (*Printer) PromptForEnter ¶ added in v0.3.0
Prompts the user for confirmation by pressing Enter.
Returns nil if the user presses Enter.
func (*Printer) PromptForPassword ¶ added in v0.5.0
Prompts the user for a password.
Returns the password that was given, otherwise returns error