gen

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Code generated by apic; DO NOT EDIT.

Code generated by apic; DO NOT EDIT.

Package gen is a generic general use Go functions library which can be used throughout any project.

As a rule the methods in this package are non-destructive and return a new value rather than modifying the original. Code generated by apic; DO NOT EDIT.

Code generated by apic; DO NOT EDIT.

Code generated by apic; DO NOT EDIT.

Code generated by apic; DO NOT EDIT.

Code generated by apic; DO NOT EDIT.

Code generated by apic; DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[T any](in ...T) []T

As allows you to cast N values passed in through a variadic argument to a slice of N values. This is useful for casting disparate struct types to slices of implemented interfaces

Example: As[io.Reader](&bytes.Buffer{}, &bufio.Reader{})

func Close

func Close[U channel[T], T any](in ...U)

Close closes all channels in the input slice

NOTE: If a channel is already closed any panic will be ignored and the channel will be skipped

func Compare

func Compare[T comparable](a, b []T) error

Compare returns nil if the two input slices are equal otherwise it returns an error indicating the issue

func Diff

func Diff[T comparable](a, b []T) []T

Diff returns the symmetric difference between the two input slices

func Equal

func Equal[T comparable](a, b []T) bool

Equal returns true if the two input slices are exactly equal

func Exclude

func Exclude[T comparable](a []T, b ...T) []T

Exclude returns a slice of values from the input slice minus the values supplied in the second argument

func Has

func Has[T comparable](in []T, v T) bool

Has determines if the input slice contains the input value

func Index

func Index[T comparable](in []T, v T) int

Index returns the index of the first occurrence of the input value

func Indices

func Indices[T comparable](in []T, v T) []int

Indices returns a slice of indices for all occurrences of value `v`

func Intersect

func Intersect[T comparable](a, b []T) []T

Intersect returns the intersection between the two input slices

func Match

func Match[T comparable](a, b []T) bool

Match returns true if the two input slices contain equivalent values NOTE: Match ignores ordering

func PanicDetail added in v0.18.3

func PanicDetail() bool

PanicDetail reports whether panic detail (value + stack) is currently enabled.

func ReadOnly

func ReadOnly[U chan T, T any](in ...U) []<-chan T

ReadOnly accepts a slice of channels and returns a slice of channels that are read-only.

func SafeGo

func SafeGo(name string, fn func())

SafeGo launches fn in a goroutine with panic recovery. Panics are logged via slog.Error and counted in the "panics" expvar.

func SafeLoop

func SafeLoop(name string, stop <-chan struct{}, fn func(stop <-chan struct{}))

SafeLoop launches fn in a goroutine that restarts on panic with exponential backoff (100ms to 5s cap). Stops when stop closes.

func SetPanicDetail added in v0.18.3

func SetPanicDetail(on bool)

SetPanicDetail toggles whether SafeGo/SafeLoop log the raw panic value and full goroutine stack on recovery. Default false. Generated servers wire this to APIC_LOG_PANIC_DETAIL=1 (see server_lib.go.tmpl / cli/serve) so an operator can opt into full detail for debugging without a rebuild.

func Unique

func Unique[U ~[]T, T comparable](in U) []T

Unique returns a slice of unique values from the input slice

func WriteOnly

func WriteOnly[U chan T, T any](in ...U) []chan<- T

WriteOnly accepts a slice of channels and returns a slice of channels that are write-only.

Types

type FMap

type FMap[K, V comparable] Map[K, V]

FMap is a flippale map where the key and value can be swapped

func (FMap[K, V]) Flip

func (m FMap[K, V]) Flip() FMap[V, K]

Flip returns a new FMap with the key and value swapped

type FileUpload

type FileUpload struct {
	Filename    string
	Size        int64
	ContentType string
	Reader      io.Reader
}

FileUpload represents a parsed multipart file upload.

Ownership contract (G-06): Reader is deliberately typed io.Reader, not io.ReadCloser. On the SERVER side, the generated REST handler (internal/generator/templates/api.go.tmpl) is the sole owner of the underlying multipart.File/os.File descriptor: it opens every file part, hands this struct to your business handler for the duration of one request, and closes every opened descriptor itself (via a deferred cleanup covering both the success path and every early-rejection return) once the request finishes. Do not attempt to Close Reader yourself on the server side -- there is nothing to close through this interface, by design, so a double-close footgun is structurally impossible. On the CLIENT side, callers construct a FileUpload to describe an outbound upload (see the generated Go/Python/Rust/Zig client multipart encoders); Reader there is typically backed by an in-memory value (strings.Reader, bytes.Reader) or a caller-owned *os.File that the CALLER opened and remains responsible for closing -- io.Reader is the correct, minimal type for that role too.

type IndexMismatchError

type IndexMismatchError[T any] struct {
	I        int
	Expected T
	Actual   T
}

IndexMismatchError reports that the element at index I of a generic collection did not match what was expected: Expected holds the wanted value and Actual the value actually found there.

func (IndexMismatchError[T]) Error

func (e IndexMismatchError[T]) Error() string

Error implements the error interface, formatting the expected and actual values that differed at e.I.

type LengthMismatchError

type LengthMismatchError struct {
	Expected int
	Actual   int
}

LengthMismatchError reports that a collection's length did not match what was expected: Expected holds the wanted length and Actual the length actually observed.

func (LengthMismatchError) Error

func (e LengthMismatchError) Error() string

Error implements the error interface, formatting the expected and actual lengths that differed.

type Map

type Map[K comparable, V any] map[K]V

Map wraps the Go map type in a generic which provides helper functions for accessing slices of keys or values without repeating the the implementation for each type

func (Map[K, V]) Keys

func (m Map[K, V]) Keys() []K

Keys returns a slice of keys from the map

func (Map[K, V]) Values

func (m Map[K, V]) Values() []V

Values returns a slice of values from the map

type Slice

type Slice[T comparable] []T

Slice wraps a slice of values with helper functions

func (Slice[T]) Chan

func (s Slice[T]) Chan(ctx context.Context) <-chan T

Chan converts the slice to a channel of type T

NOTE: This function does NOT use a buffered channel.

func (Slice[T]) Map

func (s Slice[T]) Map() Map[T, any]

Map returns a map of the given slice where the values of the slice are the Map keys

Directories

Path Synopsis
Code generated by apic; DO NOT EDIT.
Code generated by apic; DO NOT EDIT.

Jump to

Keyboard shortcuts

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