Documentation
¶
Overview ¶
Package done: Simple error handling package with panic-based validation Auto panics on errors to simplify error checking patterns in Go code Supports validation functions that reduce boilerplate error handling Provides type-safe validation methods with inline assertions
done: Go 错误处理简化包,基于 panic 的验证机制 错误时自动 panic,简化 Go 代码中的错误检查模式 支持验证函数,减少样板错误处理代码 提供类型安全的验证方法和内联断言
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 Done(err error)
- func Fata(err error)
- func Fine[V comparable](v V)
- func Full[T any](v *T) *T
- func Good[V comparable](v V)
- func Must(err error)
- func Nice[V comparable](v V) V
- func None[V comparable](v V)
- func Null[T any](v *T)
- 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 Safe[V comparable](v V)
- func Soft(err error)
- func Sure[V comparable](v V) V
- 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 Zero[V comparable](v V)
- type Vae
- func (a *Vae[V]) Fine()
- func (a *Vae[V]) Good()
- func (a *Vae[V]) Have()
- func (a *Vae[V]) Len(n int)
- func (a *Vae[V]) Length(n int)
- func (a *Vae[V]) Nice() []V
- func (a *Vae[V]) None()
- func (a *Vae[V]) Safe()
- func (a *Vae[V]) Size(n int)
- func (a *Vae[V]) Some() []V
- func (a *Vae[V]) Sure() []V
- func (a *Vae[V]) Void()
- func (a *Vae[V]) Zero()
- type Vbe
- type Vce
- func (a *Vce[V]) Diff(v V)
- func (a *Vce[V]) Different(v V)
- func (a *Vce[V]) Equals(v V)
- func (a *Vce[V]) Fine()
- func (a *Vce[V]) Good()
- func (a *Vce[V]) Is(v V)
- func (a *Vce[V]) Nice() V
- func (a *Vce[V]) None()
- func (a *Vce[V]) Safe()
- func (a *Vce[V]) Same(v V)
- func (a *Vce[V]) Sure() V
- func (a *Vce[V]) Zero()
- type Ve
- type Vme
- func (a *Vme[K, V]) Fine()
- func (a *Vme[K, V]) Good()
- func (a *Vme[K, V]) Have()
- func (a *Vme[K, V]) Len(n int)
- func (a *Vme[K, V]) Length(n int)
- func (a *Vme[K, V]) Nice() map[K]V
- func (a *Vme[K, V]) None()
- func (a *Vme[K, V]) Safe()
- func (a *Vme[K, V]) Size(n int)
- func (a *Vme[K, V]) Some() map[K]V
- func (a *Vme[K, V]) Sure() map[K]V
- func (a *Vme[K, V]) Void()
- func (a *Vme[K, V]) Zero()
- type Vne
- type Vpe
- type Vse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func C0 ¶ added in v1.0.16
func C0(err error)
C0 checks error and panics if exists. C0 检查错误,存在则触发 panic。
func C1 ¶ added in v1.0.16
func C1[T1 comparable](v1 T1, err error) T1
C1 checks error, ensures value is not zero, and returns the value. C1 检查错误,确保值非零,并返回值。
func C2 ¶ added in v1.0.16
func C2[T1, T2 comparable](v1 T1, v2 T2, err error) (T1, T2)
C2 checks error, ensures values are not zero, and returns the values. C2 检查错误,确保值非零,并返回值。
func Done ¶
func Done(err error)
Done panics and logs the stack trace if the error occurs, otherwise do nothing Done 当err非空时就panic且打印调用栈信息
func Fata ¶
func Fata(err error)
Fata logs a fatal error and exits the system if the error occurs, otherwise do nothing Fata 当出错时就是调用 log.Fatal 退出系统,当不出错时就不做任何事情
func Fine ¶
func Fine[V comparable](v V)
Fine ensures the value is not zero. Panics if the value equals its zero value. Fine 确保值非零。 如果值等于零值则触发 panic。
func Full ¶ added in v1.0.16
func Full[T any](v *T) *T
Full ensures the pointer is not nil and returns it. Panics if the pointer is nil. Full 确保指针非 nil 并返回该指针。 如果指针是 nil 则触发 panic。
func Good ¶
func Good[V comparable](v V)
Good ensures the value is not zero. Panics if the value equals its zero value. Good 确保值非零。 如果值等于零值则触发 panic。
func Must ¶
func Must(err error)
Must panics and logs the stack trace if the error occurs, otherwise do nothing Must 当err非空时就panic且打印调用栈信息
func Nice ¶
func Nice[V comparable](v V) V
Nice ensures the value is not zero and returns it. Panics if the value equals its zero value. Nice 确保值非零并返回该值。 如果值等于零值则触发 panic。
func None ¶
func None[V comparable](v V)
None ensures the value is its type's zero value. Panics if the value is not zero. None 确保值是其类型的零值。 如果值非零则触发 panic。
func Null ¶ added in v1.0.16
func Null[T any](v *T)
Null ensures the pointer is nil. Panics if the pointer is not nil. Null 确保指针是 nil。 如果指针非 nil 则触发 panic。
func P0 ¶ added in v1.0.16
func P0(err error)
P0 checks error and panics if exists. P0 检查错误,存在则触发 panic。
func P1 ¶ added in v1.0.16
P1 checks error, ensures pointer is not nil, and returns the pointer. P1 检查错误,确保指针非 nil,并返回指针。
func P2 ¶ added in v1.0.16
P2 checks error, ensures pointers are not nil, and returns the pointers. P2 检查错误,确保指针非 nil,并返回指针。
func Safe ¶
func Safe[V comparable](v V)
Safe ensures the value is not zero. Panics if the value equals its zero value. Safe 确保值非零。 如果值等于零值则触发 panic。
func Soft ¶
func Soft(err error)
Soft logs a warning and the stack trace if the error occurs, otherwise do nothing Soft 当err非空时就打印warning日志且打印调用栈信息
func Sure ¶
func Sure[V comparable](v V) V
Sure ensures the value is not zero and returns it. Panics if the value equals its zero value. Sure 确保值非零并返回该值。 如果值等于零值则触发 panic。
func V0 ¶ added in v1.0.16
func V0(err error)
V0 checks error and panics if exists. V0 检查错误,存在则触发 panic。
func Zero ¶
func Zero[V comparable](v V)
Zero ensures the value is its type's zero value. Panics if the value is not zero (e.g., num is not 0, string is not "", pointer is not nil). Zero 确保值是其类型的零值。 如果值非零则触发 panic(例如数字非0、字符串非空、指针非nil)。
Types ¶
type Vae ¶
Vae wraps a slice value and an error with slice validation methods. Embeds Ve to provide basic error handling methods. A means slice type. Vae 封装一个切片值和一个错误,配合切片验证方法。 嵌入 Ve 来提供基础错误处理方法。A 代表切片类型。
func VAE ¶
VAE creates a Vae instance with a slice value and error. Accepts two params: one is slice and one is error interface. VAE 创建一个 Vae 实例,包含切片值和错误。 接受两个参数:切片和错误接口。
func (*Vae[V]) Fine ¶
func (a *Vae[V]) Fine()
Fine ensures no error and slice is not empty. Fine 确保无错误且切片非空。
func (*Vae[V]) Good ¶
func (a *Vae[V]) Good()
Good ensures no error and slice is not empty. Good 确保无错误且切片非空。
func (*Vae[V]) Have ¶
func (a *Vae[V]) Have()
Have ensures no error and slice is not empty. Have 确保无错误且切片非空。
func (*Vae[V]) Length ¶
Length ensures no error and slice has the given length. Length 确保无错误且切片长度等于给定值。
func (*Vae[V]) Nice ¶
func (a *Vae[V]) Nice() []V
Nice ensures no error and slice is not empty, then returns the slice. Nice 确保无错误且切片非空,然后返回切片。
func (*Vae[V]) None ¶
func (a *Vae[V]) None()
None ensures no error and slice is empty. None 确保无错误且切片是空的。
func (*Vae[V]) Safe ¶
func (a *Vae[V]) Safe()
Safe ensures no error and slice is not empty. Safe 确保无错误且切片非空。
func (*Vae[V]) Some ¶
func (a *Vae[V]) Some() []V
Some ensures no error and slice is not empty, then returns the slice. Some 确保无错误且切片非空,然后返回切片。
func (*Vae[V]) Sure ¶
func (a *Vae[V]) Sure() []V
Sure ensures no error and slice is not empty, then returns the slice. Sure 确保无错误且切片非空,然后返回切片。
type Vbe ¶
Vbe wraps a boolean value and an error with boolean validation methods. Embeds Vce to provide comparable validation methods. Vbe 封装一个布尔值和一个错误,配合布尔验证方法。 嵌入 Vce 来提供可比较验证方法。
func (*Vbe) FALSE ¶
func (a *Vbe) FALSE()
FALSE ensures no error and value is false. FALSE 确保无错误且值是 false。
type Vce ¶
type Vce[V comparable] struct { V V E error *Ve[V] }
Vce wraps a comparable value and an error with validation methods. Embeds Ve to provide basic error handling methods. Vce 封装一个可比较值和一个错误,配合验证方法。 嵌入 Ve 来提供基础错误处理方法。
func VCE ¶
func VCE[V comparable](val V, err error) *Vce[V]
VCE creates a Vce instance with a comparable value and error. Accepts two params: one is comparable value and one is error interface. VCE 创建一个 Vce 实例,包含可比较值和错误。 接受两个参数:可比较值和错误接口。
func (*Vce[V]) Diff ¶
func (a *Vce[V]) Diff(v V)
Diff ensures no error and value is not equal to the given value. Diff 确保无错误且值不等于给定值。
func (*Vce[V]) Different ¶
func (a *Vce[V]) Different(v V)
Different ensures no error and value is not equal to the given value. Different 确保无错误且值不等于给定值。
func (*Vce[V]) Equals ¶
func (a *Vce[V]) Equals(v V)
Equals ensures no error and value equals the given value. Equals 确保无错误且值等于给定值。
func (*Vce[V]) Fine ¶
func (a *Vce[V]) Fine()
Fine ensures no error and value is not zero. Fine 确保无错误且值非零。
func (*Vce[V]) Good ¶
func (a *Vce[V]) Good()
Good ensures no error and value is not zero. Good 确保无错误且值非零。
func (*Vce[V]) Is ¶
func (a *Vce[V]) Is(v V)
Is ensures no error and value equals the given value. Is 确保无错误且值等于给定值。
func (*Vce[V]) Nice ¶
func (a *Vce[V]) Nice() V
Nice ensures no error and value is not zero, then returns the value. Nice 确保无错误且值非零,然后返回值。
func (*Vce[V]) None ¶
func (a *Vce[V]) None()
None ensures no error and value is zero. None 确保无错误且值是零值。
func (*Vce[V]) Safe ¶
func (a *Vce[V]) Safe()
Safe ensures no error and value is not zero. Safe 确保无错误且值非零。
func (*Vce[V]) Same ¶
func (a *Vce[V]) Same(v V)
Same ensures no error and value equals the given value. Same 确保无错误且值等于给定值。
type Ve ¶
Ve wraps a value and an error with validation methods. Ve 封装一个值和一个错误,配合验证方法。
func VE ¶
VE creates a Ve instance with a value and error. Accepts two params: one is any value and one is error interface. VE 创建一个 Ve 实例,包含值和错误。 接受两个参数:任意值和错误接口。
func (*Ve[V]) Done ¶
func (a *Ve[V]) Done() V
Done checks if error exists and panics, then returns the value. The value is not checked and can be zero. Done 检查是否存在错误并触发 panic,然后返回值。 不检查值,可以是零值。
func (*Ve[V]) Must ¶
func (a *Ve[V]) Must() V
Must checks if error exists and panics, then returns the value. The value is not checked and can be zero. Must 检查是否存在错误并触发 panic,然后返回值。 不检查值,可以是零值。
func (*Ve[V]) Omit ¶
func (a *Ve[V]) Omit() V
Omit returns the value and ignores the error. The value can be normal, zero, or unexpected. Omit 返回值并忽视错误。 值可能是正常值、零值或异常值。
type Vme ¶
type Vme[K comparable, V any] struct { V map[K]V E error *Ve[map[K]V] }
Vme wraps a map value and an error with map validation methods. Embeds Ve to provide basic error handling methods. M means map type. Vme 封装一个 map 值和一个错误,配合 map 验证方法。 嵌入 Ve 来提供基础错误处理方法。M 代表 map 类型。
func VME ¶
func VME[K comparable, V any](val map[K]V, err error) *Vme[K, V]
VME creates a Vme instance with a map value and error. Accepts two params: one is map and one is error interface. VME 创建一个 Vme 实例,包含 map 值和错误。 接受两个参数:map 和错误接口。
func (*Vme[K, V]) Fine ¶
func (a *Vme[K, V]) Fine()
Fine ensures no error and map is not empty. Fine 确保无错误且 map 非空。
func (*Vme[K, V]) Good ¶
func (a *Vme[K, V]) Good()
Good ensures no error and map is not empty. Good 确保无错误且 map 非空。
func (*Vme[K, V]) Have ¶
func (a *Vme[K, V]) Have()
Have ensures no error and map is not empty. Have 确保无错误且 map 非空。
func (*Vme[K, V]) Length ¶
Length ensures no error and map has the given length. Length 确保无错误且 map 长度等于给定值。
func (*Vme[K, V]) Nice ¶
func (a *Vme[K, V]) Nice() map[K]V
Nice ensures no error and map is not empty, then returns the map. Nice 确保无错误且 map 非空,然后返回 map。
func (*Vme[K, V]) None ¶
func (a *Vme[K, V]) None()
None ensures no error and map is empty. None 确保无错误且 map 是空的。
func (*Vme[K, V]) Safe ¶
func (a *Vme[K, V]) Safe()
Safe ensures no error and map is not empty. Safe 确保无错误且 map 非空。
func (*Vme[K, V]) Some ¶
func (a *Vme[K, V]) Some() map[K]V
Some ensures no error and map is not empty, then returns the map. Some 确保无错误且 map 非空,然后返回 map。
func (*Vme[K, V]) Sure ¶
func (a *Vme[K, V]) Sure() map[K]V
Sure ensures no error and map is not empty, then returns the map. Sure 确保无错误且 map 非空,然后返回 map。
type Vne ¶
Vne wraps a numeric value and an error with numeric validation methods. Embeds Vce to provide comparable validation methods. Vne 封装一个数字值和一个错误,配合数字验证方法。 嵌入 Vce 来提供可比较验证方法。
func (*Vne[V]) Gt ¶
func (a *Vne[V]) Gt(base V) V
Gt ensures no error and value is greater than base, then returns the value. Gt 确保无错误且值大于基准值,然后返回值。
func (*Vne[V]) Gte ¶
func (a *Vne[V]) Gte(base V) V
Gte ensures no error and value is greater than or equal to base, then returns the value. Gte 确保无错误且值大于等于基准值,然后返回值。
type Vpe ¶
Vpe wraps a pointer value and an error with validation methods. Embeds Ve to provide basic error handling methods. Vpe 封装一个指针值和一个错误,配合验证方法。 嵌入 Ve 来提供基础错误处理方法。
func VPE ¶
VPE creates a Vpe instance with a pointer value and error. Accepts two params: one is pointer and one is error interface. VPE 创建一个 Vpe 实例,包含指针值和错误。 接受两个参数:指针和错误接口。
func (*Vpe[V]) Fine ¶
func (a *Vpe[V]) Fine()
Fine ensures no error and pointer is not nil. Fine 确保无错误且指针非 nil。
func (*Vpe[V]) Full ¶ added in v1.0.16
func (a *Vpe[V]) Full() *V
Full ensures no error and pointer is not nil, then returns the pointer. Full 确保无错误且指针非 nil,然后返回指针。
func (*Vpe[V]) Good ¶
func (a *Vpe[V]) Good()
Good ensures no error and pointer is not nil. Good 确保无错误且指针非 nil。
func (*Vpe[V]) Nice ¶
func (a *Vpe[V]) Nice() *V
Nice ensures no error and pointer is not nil, then returns the pointer. Nice 确保无错误且指针非 nil,然后返回指针。
func (*Vpe[V]) None ¶
func (a *Vpe[V]) None()
None ensures no error and pointer is nil. None 确保无错误且指针是 nil。
func (*Vpe[V]) Null ¶ added in v1.0.16
func (a *Vpe[V]) Null()
Null ensures no error and pointer is nil. Null 确保无错误且指针是 nil。
func (*Vpe[V]) Safe ¶
func (a *Vpe[V]) Safe()
Safe ensures no error and pointer is not nil. Safe 确保无错误且指针非 nil。
type Vse ¶
Vse wraps a string value and an error with string validation methods. Embeds Vce to provide comparable validation methods. Vse 封装一个字符串值和一个错误,配合字符串验证方法。 嵌入 Vce 来提供可比较验证方法。
func (*Vse) Contains ¶
Contains ensures no error and string contains the given substring. Contains 确保无错误且字符串包含给定子串。
func (*Vse) Equals ¶
Equals ensures no error and string equals the given string. Equals 确保无错误且字符串等于给定字符串。