Documentation
¶
Overview ¶
Package ensure provides assertion utilities for development. Assertions are used to catch programming errors early.
Deep-Ensure: 早暴露 + 契约化 + 零容忍 + 性能友好
Index ¶
- Variables
- func NoError(err error, format string, args ...any)
- func NoError1[T1 any](err error, format string, arg1 T1)
- func NoError2[T1, T2 any](err error, format string, arg1 T1, arg2 T2)
- func NotNil(obj any, format string, args ...any)
- func NotNil1[T1 any](obj any, format string, arg1 T1)
- func NotNil2[T1, T2 any](obj any, format string, arg1 T1, arg2 T2)
- func SetDebugMode(enabled bool)
- func TODO(format string, args ...any)
- func True(condition bool, format string, args ...any)
- func True1[T1 any](condition bool, format string, arg1 T1)
- func True1Dbg[T1 any](condition bool, format string, arg1 T1)
- func True2[T1, T2 any](condition bool, format string, arg1 T1, arg2 T2)
- func True2Dbg[T1, T2 any](condition bool, format string, arg1 T1, arg2 T2)
- func True3[T1, T2, T3 any](condition bool, format string, arg1 T1, arg2 T2, arg3 T3)
- func TrueDbg(condition bool, format string, args ...any)
- func Unreachable(format string, args ...any)
Constants ¶
This section is empty.
Variables ¶
var OnFailed = func(msg string) { panic(msg) }
OnFailed is called when an assertion fails. Can be overridden for testing or custom behavior.
Functions ¶
func NoError ¶
NoError asserts that err is nil. If not nil, panics with error details.
Usage:
ensure.NoError(json.Unmarshal(data, &obj), "failed to parse config")
func NotNil ¶
NotNil asserts that obj is not nil. If nil, panics with formatted message.
Usage:
ensure.NotNil(db, "database connection required")
func SetDebugMode ¶
func SetDebugMode(enabled bool)
SetDebugMode enables or disables debug-only assertions.
func TODO ¶
TODO marks incomplete implementation. Panics with a message about unimplemented functionality.
Usage:
func NewFeature() {
ensure.TODO("NewFeature not implemented yet")
}
func True ¶
True asserts that condition is true. If false, panics with formatted message.
Usage:
ensure.True(len(items) > 0, "items must not be empty") ensure.True(user != nil, "user %s not found", userID)
func TrueDbg ¶
TrueDbg asserts that condition is true, but only in debug mode. In release mode, this is a no-op.
Usage:
ensure.TrueDbg(index >= 0 && index < len(arr), "index out of bounds: %d", index)
func Unreachable ¶
Unreachable marks code that should never be reached. Always panics.
Usage:
switch status {
case Running:
// ...
default:
ensure.Unreachable("unexpected status: %d", status)
}
Types ¶
This section is empty.