helpers

package
v0.12.19 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BroadcastIP

func BroadcastIP(network *net.IPNet) (*net.IP, error)

BroadcastIP returns the IPv4 broadcast address for the given network. An error is returned when the supplied IPNet is not IPv4 compatible.

func GenerateHashSHA512

func GenerateHashSHA512(data io.ReadCloser) []byte

GenerateHashSHA512 streams the provided reader through SHA-512 and returns the resulting digest. Callers are responsible for closing the reader.

func PanicOnError

func PanicOnError(e error)

PanicOnError aborts execution when the supplied error is non-nil. It centralizes defensive checks so call sites stay readable.

func PanicOnError2

func PanicOnError2[T any](v T, e error) T

PanicOnError2 returns the provided value while panicking if the error is non-nil. It is useful when callers want the familiar value, err signature but still treat non-nil errors as fatal.

func SignalHandler

func SignalHandler(applicationMain func(), shutdownHandler func(), signals ...os.Signal)

SignalHandler runs applicationMain asynchronously and blocks until one of the provided OS signals arrives, then invokes shutdownHandler for cleanup.

func StripError

func StripError[T any](v T, e error) T

StripError discards the error return and yields the first value. It should be used sparingly and primarily in code paths with guaranteed correctness.

Types

type Optional

type Optional[T any] struct {
	// contains filtered or unexported fields
}

Optional wraps a value that may or may not be specified. Remember to pass pointer types when zero values would be ambiguous.

func NewOptional

func NewOptional[T any](initial T) Optional[T]

NewOptional produces a new Optional with an initial value and unspecified state. The value is returned until Specify is called.

func (*Optional[T]) Get

func (opt *Optional[T]) Get() T

Get returns the stored value regardless of specification state.

func (*Optional[T]) Specified

func (opt *Optional[T]) Specified() bool

Specified reports whether a caller previously invoked Specify.

func (*Optional[T]) Specify

func (opt *Optional[T]) Specify(value T)

Specify records a concrete value and flips the internal specified flag.

Source Files

  • ErrorHandling.go
  • Hashing.go
  • Net.go
  • OSSignals.go
  • Optional.go

Jump to

Keyboard shortcuts

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