util

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultErrorExitCode defines the default exit code.
	DefaultErrorExitCode = 1
)

Variables

View Source
var ErrExit = fmt.Errorf("exit")

ErrExit may be passed to CheckError to instruct it to output nothing but exit with status code 1.

Functions

func BehaviorOnFatal

func BehaviorOnFatal(f func(string, int))

BehaviorOnFatal allows you to override the default behavior when a fatal error occurs, which is to call os.Exit(code). You can pass 'panic' as a function here if you prefer the panic() over os.Exit(1).

func CheckErr

func CheckErr(err error)

CheckErr prints a user-friendly error to STDERR and exits with a non-zero exit code. Unrecognized errors will be printed with an "error: " prefix.

This method is generic to the command in use and may be used by non-IAM commands.

func DefaultBehaviorOnFatal

func DefaultBehaviorOnFatal()

DefaultBehaviorOnFatal allows you to undo any previous override. Useful in tests.

func MultipleErrors

func MultipleErrors(prefix string, errs []error) string

MultipleErrors returns a newline delimited string containing the prefix and referenced errors in standard form.

func StandardErrorMessage

func StandardErrorMessage(err error) (string, bool)

StandardErrorMessage translates common errors into a human-readable message, or returns false if the error is not one of the recognized types. It may also log extended information to log.

This method is generic to the command in use and may be used by non-IAM commands.

Types

type Factory

type Factory interface {
	HTTPClient() *http.Client
	// AdminClient returns a HivemindAdminService gRPC client connected to the given address.
	// The caller is responsible for closing the returned connection.
	AdminClient(addr string) (pb.HivemindAdminServiceClient, *grpc.ClientConn, error)
	// HivemindAddr returns the configured Hivemind gRPC address.
	HivemindAddr() string
}

Factory provides abstractions that allow the echoctl command to be extended across multiple types of resources and different API sets.

func NewDefaultFactory

func NewDefaultFactory(hivemindAddr *string) Factory

NewDefaultFactory creates a Factory. The hivemindAddr pointer should point to the global flag variable that holds the Hivemind address.

Jump to

Keyboard shortcuts

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