package gocompat
import "github.com/cyphar/filepath-securejoin/pathrs-lite/internal/gocompat"
Package gocompat includes compatibility shims (backported from future Go stdlib versions) to permit filepath-securejoin to be used with older Go versions (often filepath-securejoin is added in security patches for old releases, so avoiding the need to bump Go compiler requirements is a huge plus to downstreams).
Index ¶
- func CmpCompare[T CmpOrdered](x, y T) int
- func Max2[T CmpOrdered](x, y T) T
- func SlicesClone[S ~[]E, E any](slice S) S
- func SlicesContains[S ~[]E, E comparable](slice S, val E) bool
- func SlicesDeleteFunc[S ~[]E, E any](slice S, delFn func(E) bool) S
- func SyncOnceValue[T any](f func() T) func() T
- func SyncOnceValues[T1, T2 any](f func() (T1, T2)) func() (T1, T2)
- func WrapBaseError(baseErr, extraErr error) error
- type Bool
- type CmpOrdered
Functions ¶
func CmpCompare ¶
func CmpCompare[T CmpOrdered](x, y T) int
CmpCompare is equivalent to Go 1.21's cmp.Compare.
func Max2 ¶
func Max2[T CmpOrdered](x, y T) T
Max2 is equivalent to Go 1.21's max builtin (but only for two parameters).
func SlicesClone ¶
func SlicesClone[S ~[]E, E any](slice S) S
SlicesClone is equivalent to Go 1.21's slices.Clone.
func SlicesContains ¶
func SlicesContains[S ~[]E, E comparable](slice S, val E) bool
SlicesContains is equivalent to Go 1.21's slices.Contains.
func SlicesDeleteFunc ¶
SlicesDeleteFunc is equivalent to Go 1.21's slices.DeleteFunc.
func SyncOnceValue ¶
func SyncOnceValue[T any](f func() T) func() T
SyncOnceValue is equivalent to Go 1.21's sync.OnceValue.
func SyncOnceValues ¶
func SyncOnceValues[T1, T2 any](f func() (T1, T2)) func() (T1, T2)
SyncOnceValues is equivalent to Go 1.21's sync.OnceValues.
func WrapBaseError ¶
WrapBaseError is a helper that is equivalent to fmt.Errorf("%w: %w"), except that on pre-1.20 Go versions only errors.Is() works properly (errors.Unwrap) is only guaranteed to give you baseErr.
Types ¶
type Bool ¶
A Bool is an atomic boolean value. The zero value is false.
Bool must not be copied after first use.
type CmpOrdered ¶
CmpOrdered is equivalent to Go 1.21's cmp.Ordered generic type definition.
Source Files ¶
doc.go gocompat_atomic_go119.go gocompat_errors_go120.go gocompat_generics_go121.go
- Version
- v0.6.1 (latest)
- Published
- Nov 19, 2025
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 4 hours ago –
Tools for package owners.