Documentation ¶
Overview ¶
Package contract provides support for runtime "Programming by Contract" checks.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Conditions ¶
Conditions checks the expression(s) given to see that they are all true. If any fail a suitable error message is logged and the program is halted if os.Exit(1).
This method should typically not be called near the start or end of a method, however that is not a requirement. (In fact Preconditions, Conditions, and Postconditions all do exactly the same thing except for a slight difference in the message that is logged. The three methods are provided instead of one simply as a means of documenting their intent.)
func Postconditions ¶
Postconditions checks the expression(s) given to see that they are all true. If any fail a suitable error message is logged and the program is halted if os.Exit(1).
This method should typically be called near the end of a method, possibly right after the parameter checking. However, that is not a requirement. (In fact Preconditions, Conditions, and Postconditions all do exactly the same thing except for a slight difference in the message that is logged. The three methods are provided instead of one simply as a means of documenting their intent.)
Typically this is called to check the post-conditions of a successful execution of the function. As such it is generally not run when errors cause an early exit. However, if you wish it to run in such cases, you can add defer before the call.
func Preconditions ¶
Preconditions checks the expression(s) given to see that they are all true. If any fail a suitable error message is logged and the program is halted if os.Exit(1).
This method should typically be called near the start of a method, possibly right after the parameter checking. However, that is not a requirement. (In fact Preconditions, Conditions, and Postconditions all do exactly the same thing except for a slight difference in the message that is logged. The three methods are provided instead of one simply as a means of documenting their intent.)
Types ¶
type Invariant ¶
type Invariant struct {
// contains filtered or unexported fields
}
Invariant marks that a given item must not change within the method.
func NewInvariant ¶
func NewInvariant(obj interface{}) Invariant
NewInvariant constructs an Invariant wrapping a given object. Note that obj needs to be a pointer to a struct. This code does not work with types such as integers or strings as they end up being copied hence any changes are not seen.