Documentation
¶
Index ¶
- func Cond(cond bool, msg string)
- func CondF(cond bool, format string, args ...any)
- func Conv[T any](obj any, name string) T
- func Err(inner error, format string, args ...any)
- func Fix(name string, obj Fixer, allow_nil bool)
- func New[T gers.Pointer](obj T, inner error) T
- func NotNil(obj any, name string)
- func NotOk(ok bool, format string, args ...any)
- func NotZero[T comparable](obj T, name string)
- func Ok(ok bool, format string, args ...any)
- func Type[T any](obj any, name string, allow_nil bool)
- func Validate(name string, obj Validater, allow_nil bool)
- type ErrorCode
- type Fixer
- type Validater
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cond ¶
Cond asserts that a condition is true.
If the condition is false, it calls panic() with an error.Err with the code AssertFail and the given message.
Parameters:
- cond: The condition to assert.
- msg: The message to use if the condition is false.
func CondF ¶
CondF asserts that a condition is true.
If the condition is false, it calls panic() with an error.Err with the code AssertFail and a message that includes the formatted string.
Parameters:
- cond: The condition to assert.
- format: The format string to use for the message.
- args: The arguments to pass to the format string.
func Conv ¶
Conv asserts that the given object can be converted to type T.
If the object can be converted to type T, it returns the converted value. Otherwise, it calls panic() with an error.Err with the code AssertFail and a message that includes the original object and its expected type.
Parameters:
- obj: The object to convert to type T.
- name: The name of the object to use for the error message.
Returns:
- T: The converted value.
func Err ¶
Err asserts that an error is nil.
If the error is not nil, it calls panic() with an error.Err with the code AssertFail and a message that includes the original error.
Parameters:
- err: The error to check.
- format: The format string to use for the message.
- args: The arguments to pass to the format string.
func Fix ¶
Fix fixes the object.
Parameters:
- name: The name of the object.
- obj: The object to fix.
- allow_nil: Whether to allow the object to be nil.
Panics if the object can not be fixed.
func New ¶
New asserts a constructor returns a non-zero value.
If the constructor returns a zero value, it calls panic() with an error.Err with the code AssertFail and a message that includes the original error.
Parameters:
- obj: The object returned by the constructor.
- inner: The error returned by the constructor.
Returns:
- T: The non-zero value returned by the constructor.
func NotNil ¶
NotNil asserts that the given object is not nil.
If the object is nil, it calls panic() with an error.Err with the code AssertFail and a message that includes the original object.
Parameters:
- obj: The object to assert is not nil.
- name: The name of the object to use for the error message.
func NotOk ¶
NotOk asserts that a condition is false.
If the condition is true, it calls panic() with an error.Err with the code AssertFail and a message that includes the original condition.
Parameters:
- ok: The condition to assert.
- format: The format string to use for the message.
- args: The arguments to pass to the format string.
func NotZero ¶
func NotZero[T comparable](obj T, name string)
NotZero asserts that the given object is not its zero value.
If the object is its zero value, it calls panic() with an error.Err with the code AssertFail and a message that includes the original object and its zero value.
Parameters:
- obj: The object to assert is not its zero value.
- name: The name of the object to use for the error message.
func Ok ¶
Ok asserts that a condition is true.
If the condition is false, it calls panic() with an error.Err with the code AssertFail and a message that includes the original condition.
Parameters:
- ok: The condition to assert.
- format: The format string to use for the message.
- args: The arguments to pass to the format string.
func Type ¶
Type asserts that the given object is of type T.
If the object is not of type T, it calls panic() with an error.Err with the code AssertFail and a message that includes the original object and its expected type.
Parameters:
- obj: The object to assert is of type T.
- name: The name of the object to use for the error message.
- allow_nil: Whether to allow the object to be nil.
Types ¶
type ErrorCode ¶
type ErrorCode int
ErrorCode is the type of the error code.
const ( // AssertFail occurs when a test or assertion fails. AssertFail ErrorCode = iota // InvalidState is a type of assertion that occurs when // a method is called on a struct having an invalid state. InvalidState // FailFix occurs when a struct cannot be fixed or resolved // due to an invalid internal state. FailFix )