Documentation
¶
Overview ¶
Package must provides panic-on-failure assertion utilities with structured logging Implements type-safe validation functions that panic with detailed context when expectations are not met Supports generic types enabling flexible value checking across different data types Integrates with zap logging to provide precise stack trace information
must 提供带结构化日志的 panic-on-failure 断言工具 实现类型安全的验证函数,当期望不满足时 panic 并提供详细上下文 支持泛型类型,在不同数据类型间灵活检查值 与 zap 日志集成,提供精确的堆栈跟踪信息
Index ¶
- func C0(err error)
- func C1[T1 comparable](v1 T1, err error) T1
- func C2[T1, T2 comparable](v1 T1, v2 T2, err error) (T1, T2)
- func Cause(err error) error
- func Contains[T comparable](a []T, v T)
- func Diff[V comparable](a, b V)
- func Different[V comparable](a, b V)
- func Done(err error)
- func Equals[V comparable](a, b V)
- func FALSE(v bool)
- func False(v bool)
- func Full[T any](v *T) *T
- func Have[T any](a []T) []T
- func In[T comparable](v T, a []T)
- func Is[V comparable](a, b V)
- func Ise(err, target error)
- func Len[T any](a []T, n int)
- func Length[T any](a []T, n int)
- func Must(err error)
- func Nice[V comparable](a V) V
- func None[V comparable](a V)
- func Null[T any](v *T)
- func OK[V comparable](a V)
- func Ok[V comparable](a V)
- func P0(err error)
- func P1[T1 any](v1 *T1, err error) *T1
- func P2[T1, T2 any](v1 *T1, v2 *T2, err error) (*T1, *T2)
- func Same[V comparable](a, b V)
- func SameNice[V comparable](a, b V) V
- func Sane[V comparable](a, b V) V
- func TRUE(v bool)
- func True(v bool)
- func V0(err error)
- func V1[T1 any](v1 T1, err error) T1
- func V2[T1, T2 any](v1 T1, v2 T2, err error) (T1, T2)
- func Wrong(err error)
- func Zero[V comparable](a V)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func C0 ¶
func C0(err error)
C0 validates no error occurred. Panics if error is non-nil. C0 验证没有错误发生。如果错误非 nil 则触发 panic。
func C1 ¶
func C1[T1 comparable](v1 T1, err error) T1
C1 validates no error and returns non-zero comparable value. Panics if error is non-nil / value is zero. C1 验证没有错误并返回非零可比较值。如果错误非 nil 或值为零则触发 panic。
func C2 ¶
func C2[T1, T2 comparable](v1 T1, v2 T2, err error) (T1, T2)
C2 validates no error and returns two non-zero comparable values. Panics if error is non-nil / any value is zero. C2 验证没有错误并返回两个非零可比较值。如果错误非 nil 或任何值为零则触发 panic。
func Cause ¶ added in v0.0.30
Cause expects an error to be present. Panics if error is nil, returns the error. Cause 期望存在错误。如果错误为 nil,则触发 panic;否则返回该错误。
func Contains ¶
func Contains[T comparable](a []T, v T)
Contains checks if the slice contains the value. Panics if the value is not found. Contains 检查切片是否包含该值。如果未找到该值,则触发 panic。
func Diff ¶ added in v0.0.17
func Diff[V comparable](a, b V)
Diff expects the values to be distinct. Panics if the values match. Diff 期望值不同。如果值相同,则触发 panic。
func Different ¶ added in v0.0.16
func Different[V comparable](a, b V)
Different expects the values to be distinct. Panics if the values match. Different 期望值不同。如果值相同,则触发 panic。
func Done ¶
func Done(err error)
Done expects no error. Panics if the provided error is non-nil. Done 期望没有错误。如果提供的错误不为 nil,则触发 panic。
func Equals ¶
func Equals[V comparable](a, b V)
Equals expects the values to be the same. Panics if not the same. Equals 期望值相等。如果值不相等,则触发 panic。
func FALSE ¶
func FALSE(v bool)
FALSE expects the value to be false. Panics if the value is true. FALSE 期望值为 false。如果值为 true,则触发 panic。
func False ¶
func False(v bool)
False expects the value to be false. Panics if the value is true. False 期望值为 false。如果值为 true,则触发 panic。
func Full ¶
func Full[T any](v *T) *T
Full expects the value to be non-nil. Panics if the value is nil. Full 期望值为非 nil。如果值为 nil,则触发 panic。
func Have ¶
func Have[T any](a []T) []T
Have checks that the slice is not vacant. Panics if the slice is vacant. Have 检查切片是否为空。如果切片为空,则触发 panic。
func In ¶
func In[T comparable](v T, a []T)
In checks if the value is in the slice. Panics if the value is not found. In 检查值是否在切片中。如果未找到该值,则触发 panic。
func Is ¶
func Is[V comparable](a, b V)
Is expects matching values, not the logic of errors.Is, but the logic of Equals. Panics if the values do not match. Is 期望相等,不是 errors.Is 的逻辑,而是 Equals 的逻辑。如果值不相等,则触发 panic。
func Ise ¶
func Ise(err, target error)
Ise expects the errors to match, using the logic of errors.Is. Panics if not matching. Ise 期望错误相等,类似于 errors.Is 的行为。如果错误不相等,则触发 panic。
func Len ¶
Len is an abbreviation of Length, serving the same purpose. Panics if the length is not n. Len 是 Length 的缩写,功能相同。如果长度不是 n,则触发 panic。
func Length ¶
Length expects the slice to have length n. Panics if the length is not n. Length 期望切片的长度为 n。如果长度不是 n,则触发 panic。
func Must ¶
func Must(err error)
Must expects no error. Panics if the provided error is non-nil. Must 期望没有错误。如果提供的错误不为 nil,则触发 panic。
func Nice ¶
func Nice[V comparable](a V) V
Nice expects a non-zero value. Panics if the value is zero, returns the value if non-zero. Nice 期望一个非零值。如果值为零,则触发 panic;如果值非零,则返回该值。
func None ¶
func None[V comparable](a V)
None expects a zero value (vacant/absent). Panics if the value is non-zero. None 期望值为零(空)。如果值不为零,则触发 panic。
func Null ¶
func Null[T any](v *T)
Null expects the value to be nil. Panics if the value is non-nil. Null 期望值为 nil。如果值不为 nil,则触发 panic。
func OK ¶
func OK[V comparable](a V)
OK expects a non-zero value. Panics if the value is zero. Provides an alternative name based on preference. OK 期望一个非零值。如果值为零,则触发 panic。提供一个偏好的替代名称。
func Ok ¶
func Ok[V comparable](a V)
Ok expects a non-zero value. Panics if the value is zero. Ok 期望一个非零值。如果值为零,则触发 panic。
func P0 ¶
func P0(err error)
P0 validates no error occurred. Panics if error is non-nil. P0 验证没有错误发生。如果错误非 nil 则触发 panic。
func P1 ¶
P1 validates no error and returns non-nil data. Panics if error is non-nil / data is nil. P1 验证没有错误并返回非 nil 指针。如果错误非 nil 或指针为 nil 则触发 panic。
func P2 ¶
P2 validates no error and returns two non-nil data. Panics if error is non-nil / any data is nil. P2 验证没有错误并返回两个非 nil 指针。如果错误非 nil 或任何指针为 nil 则触发 panic。
func Same ¶
func Same[V comparable](a, b V)
Same expects the values to be the same. Panics if not the same. Same 期望值相等。如果值不相等,则触发 panic。
func SameNice ¶ added in v0.0.18
func SameNice[V comparable](a, b V) V
SameNice expects the values to match and be non-zero. Panics if not matching / when zero. Returns the value when conditions are met. SameNice 期望值相等且非零。如果值不相等/为零,则触发 panic。如果条件满足,则返回该值。
func Sane ¶ added in v0.0.19
func Sane[V comparable](a, b V) V
Sane means same && nice Sane 期望值相等且非零。如果值不相等/为零,则触发 panic。如果条件满足,则返回该值。
func TRUE ¶
func TRUE(v bool)
TRUE expects the value to be true. Panics if the value is false. TRUE 期望值为 true。如果值为 false,则触发 panic。
func True ¶
func True(v bool)
True expects the value to be true. Panics if the value is false. True 期望值为 true。如果值为 false,则触发 panic。
func V0 ¶
func V0(err error)
V0 validates no error occurred. Panics if error is non-nil. V0 验证没有错误发生。如果错误非 nil 则触发 panic。
func V1 ¶
V1 validates no error and returns the value. Panics if error is non-nil. V1 验证没有错误并返回值。如果错误非 nil 则触发 panic。
func V2 ¶
V2 validates no error and returns two values. Panics if error is non-nil. V2 验证没有错误并返回两个值。如果错误非 nil 则触发 panic。
func Wrong ¶ added in v0.0.30
func Wrong(err error)
Wrong expects an error to be present. Panics if error is nil. Wrong 期望存在错误。如果错误为 nil,则触发 panic。
func Zero ¶
func Zero[V comparable](a V)
Zero expects a zero value. Panics if the value is non-zero. Zero 期望值为零。如果值不为零,则触发 panic。
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
demos/demo1x
command
|
|
|
demos/demo2x
command
|
|
|
demos/demo3x
command
|
|
|
mustskip/must2
Package must2 provides assertion functions with Skip2 stack frame adjustment Implements panic-on-failure validation with 2-depth skip to produce accurate stack traces Used when assertions are wrapped by one extra function invocation Integrates with zap logging using Skip2 configuration to report correct source location
|
Package must2 provides assertion functions with Skip2 stack frame adjustment Implements panic-on-failure validation with 2-depth skip to produce accurate stack traces Used when assertions are wrapped by one extra function invocation Integrates with zap logging using Skip2 configuration to report correct source location |
|
mustskip/must3
Package must3 provides assertion functions with Skip3 stack frame adjustment Implements panic-on-failure validation with 3-depth skip to produce accurate stack traces Used when assertions are wrapped by two extra function invocations Integrates with zap logging using Skip3 configuration to report correct source location
|
Package must3 provides assertion functions with Skip3 stack frame adjustment Implements panic-on-failure validation with 3-depth skip to produce accurate stack traces Used when assertions are wrapped by two extra function invocations Integrates with zap logging using Skip3 configuration to report correct source location |
|
utils
Package utils provides support functions enabling the must assertion packages Implements generic support functions used across different assertion modules Not intended to be used outside this module, serves as support mechanism
|
Package utils provides support functions enabling the must assertion packages Implements generic support functions used across different assertion modules Not intended to be used outside this module, serves as support mechanism |
|
Package mustmap provides map-specific assertion utilities with panic-on-failure semantics Implements type-safe map validation functions using Go generics and standard maps package Supports comparison operations, length validation, and element existence checking on map types Integrates with zap structured logging to provide detailed context when assertions are not met
|
Package mustmap provides map-specific assertion utilities with panic-on-failure semantics Implements type-safe map validation functions using Go generics and standard maps package Supports comparison operations, length validation, and element existence checking on map types Integrates with zap structured logging to provide detailed context when assertions are not met |
|
Package mustnum provides numeric-specific assertion utilities with panic-on-failure semantics Implements type-safe validation functions with numeric comparison and state checking Supports numeric types spanning integers and floating-points through generic Num constraint Integrates with zap structured logging to provide detailed context when assertions are not met
|
Package mustnum provides numeric-specific assertion utilities with panic-on-failure semantics Implements type-safe validation functions with numeric comparison and state checking Supports numeric types spanning integers and floating-points through generic Num constraint Integrates with zap structured logging to provide detailed context when assertions are not met |
|
Package mustsecret provides assertion utilities with panic-on-failure semantics designed to protect sensitive data Implements validation functions that avoid logging data values to prevent information leakage Panic messages exclude data values to prevent leaking secrets in logs Integrates with zap structured logging but omits sensitive value details
|
Package mustsecret provides assertion utilities with panic-on-failure semantics designed to protect sensitive data Implements validation functions that avoid logging data values to prevent information leakage Panic messages exclude data values to prevent leaking secrets in logs Integrates with zap structured logging but omits sensitive value details |
|
Package mustslice provides slice-specific assertion utilities with panic-on-failure semantics Implements type-safe slice validation functions using Go generics and standard slices package Supports comparison operations, membership testing, and length validation on slice types Integrates with zap structured logging to provide detailed context when assertions are not met
|
Package mustslice provides slice-specific assertion utilities with panic-on-failure semantics Implements type-safe slice validation functions using Go generics and standard slices package Supports comparison operations, membership testing, and length validation on slice types Integrates with zap structured logging to provide detailed context when assertions are not met |
|
Package muststrings provides string-specific assertion utilities with panic-on-failure semantics Implements validation functions using Go standard strings package Supports length checking, prefix/suffix validation, and substring containment testing Integrates with zap structured logging to provide detailed context when assertions are not met
|
Package muststrings provides string-specific assertion utilities with panic-on-failure semantics Implements validation functions using Go standard strings package Supports length checking, prefix/suffix validation, and substring containment testing Integrates with zap structured logging to provide detailed context when assertions are not met |