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 ¶
- func As[T any](in ...T) []T
- func Close[U channel[T], T any](in ...U)
- func Compare[T comparable](a, b []T) error
- func Diff[T comparable](a, b []T) []T
- func Equal[T comparable](a, b []T) bool
- func Exclude[T comparable](a []T, b ...T) []T
- func Has[T comparable](in []T, v T) bool
- func Index[T comparable](in []T, v T) int
- func Indices[T comparable](in []T, v T) []int
- func Intersect[T comparable](a, b []T) []T
- func Match[T comparable](a, b []T) bool
- func ReadOnly[U chan T, T any](in ...U) []<-chan T
- func SafeGo(name string, fn func())
- func SafeLoop(name string, stop <-chan struct{}, fn func(stop <-chan struct{}))
- func Unique[U ~[]T, T comparable](in U) []T
- func WriteOnly[U chan T, T any](in ...U) []chan<- T
- type FMap
- type FileUpload
- type IndexMismatchError
- type LengthMismatchError
- type Map
- type Slice
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 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 Unique ¶
func Unique[U ~[]T, T comparable](in U) []T
Unique returns a slice of unique values from the input slice
Types ¶
type FMap ¶
type FMap[K, V comparable] Map[K, V]
FMap is a flippale map where the key and value can be swapped
type FileUpload ¶
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 (cmd/apic/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 ¶
func (IndexMismatchError[T]) Error ¶
func (e IndexMismatchError[T]) Error() string
type LengthMismatchError ¶
func (LengthMismatchError) Error ¶
func (e LengthMismatchError) Error() string
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
type Slice ¶
type Slice[T comparable] []T
Slice wraps a slice of values with helper functions