utils

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: BSD-3-Clause, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignValue

func AssignValue(obj interface{}, jsonName string, value interface{})

func BodyReader

func BodyReader(response runtime.ClientResponse)

func Exit

func Exit(msg string, err error)

func GetFieldValue

func GetFieldValue(obj interface{}, jsonName string) reflect.Value

func HumanizeAPIError added in v1.6.1

func HumanizeAPIError(err error) string

HumanizeAPIError rewrites generic SDK error strings into messages that tell the user what to do next. Falls back to err.Error() when nothing more specific is recognized.

Detection keys off the bracketed "[<status>]" status marker that the go-openapi runtime puts on its errors. Two shapes occur in practice:

[401] Unauthorized  &{...}                       // generic response
[POST /servers][401] createServerUnauthorized ...  // typed response

so the marker shows up either at the start of the string or right after the "[<method> <path>]" segment. Matching "[401]" only at those two anchors (start, or after a "]") catches both shapes while ignoring a bare "[401]" that merely appears inside an error payload. Matching loose words like "unauthorized" is avoided too — it would capture unrelated validation messages such as `"field 'role' has an unauthorized value"`.

func PrintError

func PrintError(err error)

PrintError prints a formatted error. Recognized API failures are rewritten as actionable guidance for the user (e.g. 401 → "run lsh login").

func Render

func Render(data []renderer.ResponseData)

Render is a convenient wrapper

func Singular

func Singular(str string) string

func TitleStr

func TitleStr(str string) string

func Untar

func Untar(source, destination string) error

func Unzip

func Unzip(source, destination string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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