util

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvNoProxy disables automatic proxy support when set to any non-empty value.
	EnvNoProxy = "LARK_CLI_NO_PROXY"
)

Variables

This section is empty.

Functions

func DetectProxyEnv added in v1.0.4

func DetectProxyEnv() (key, value string)

DetectProxyEnv returns the first proxy-related environment variable that is set, or empty strings if none are configured.

func FallbackTransport added in v1.0.4

func FallbackTransport() *http.Transport

FallbackTransport returns a shared *http.Transport singleton. It is a thin wrapper over SharedTransport retained so modules that were already on the leak-free singleton path (internal/auth, internal/cmdutil transport decorators) do not have to migrate. New code should prefer SharedTransport and treat the base as an http.RoundTripper.

func IsEmptyValue

func IsEmptyValue(v interface{}) bool

IsEmptyValue checks whether v is considered empty using reflect. Returns true for nil interface, and zero values of the underlying type (e.g. "", 0, false, empty slice/map).

func IsNil

func IsNil(v interface{}) bool

IsNil reports whether v is nil, covering both untyped nil (interface itself) and typed nil (e.g. (*T)(nil) wrapped in interface{}). Avoids direct interface{} == nil comparison .

func SharedTransport added in v1.0.16

func SharedTransport() http.RoundTripper

SharedTransport returns the base http.RoundTripper for CLI HTTP clients.

By default it returns http.DefaultTransport — the stdlib-provided process-wide singleton — so every HTTP client in the process shares one TCP connection pool, TLS session cache, and HTTP/2 state. When LARK_CLI_NO_PROXY is set it returns a separate proxy-disabled singleton clone; LARK_CLI_NO_PROXY is checked on every call, but the clone is built at most once.

The returned RoundTripper MUST NOT be mutated. Callers that need a customized transport should assert to *http.Transport and Clone() it. Using a shared base is required so persistConn readLoop/writeLoop goroutines are reused; cloning per call leaks them until IdleConnTimeout (~90s) fires.

func ToFloat64

func ToFloat64(v interface{}) (float64, bool)

ToFloat64 extracts a float64 from a value that may be float64 or json.Number. Returns (0, false) if the value is neither.

func TruncateStr

func TruncateStr(s string, n int) string

TruncateStr truncates s to at most n runes, safe for multi-byte (e.g. CJK) characters.

func TruncateStrWithEllipsis

func TruncateStrWithEllipsis(s string, n int) string

TruncateStrWithEllipsis truncates s to at most n runes (including "..." suffix).

func WarnIfProxied added in v1.0.4

func WarnIfProxied(w io.Writer)

WarnIfProxied prints a one-time warning to w when a proxy environment variable is detected and proxy is not disabled via LARK_CLI_NO_PROXY. Proxy credentials are redacted. Safe to call multiple times; only the first call prints.

Types

This section is empty.

Jump to

Keyboard shortcuts

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