Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareHashStruct ¶
The CompareHashStruct function compares the hash of the given struct with the given hash. The passed object must be a pointer to a struct. The struct must have a non-empty tag "infohash" on each of its fields, the tag value must be unique for each field. The tag value is used as the name of the field in the returned error in case of a mismatch.
If the hash matches, the function returns nil. If the hash does not match, the function returns a FieldChangedError. If there is only one field that has changed, the error contains the name of the field. If there are multiple fields that have changed, the error contains an empty string.
func HashStruct ¶
HashStruct returns an infohash of the given struct. The passed object must be a pointer to a struct. The struct must have a non-empty tag "infohash" on each of its fields, the tag value must be unique for each field. The tag value is used as the name of the field in the returned error in case of a mismatch.
The CompareHashStruct function can be used to compare the hash of a struct with a previously calculated hash and return an error if the struct has changed. The error contains the name of the field that has changed.
func TestStructDefinition ¶
This test function must be added to the unit tests in your project. It will make sure that the defined fields of the struct are not changed, which would yield all calculated hashes invalid.
Types ¶
type FieldChangedError ¶
type FieldChangedError struct {
Field string
}
func (FieldChangedError) Error ¶
func (e FieldChangedError) Error() string