Documentation ¶
Overview ¶
Package equal contains the implementation of the equal plugin, which generates the deriveEqual function.
The deriveEqual function is a faster alternative to reflect.DeepEqual.
deriveEqual(T, T) bool deriveEqual(T) func(T) bool
When goderive walks over your code it is looking for a function that:
- was not implemented (or was previously derived) and
- has a predefined prefix.
In the following code the deriveEqual function will be found, because it was not implemented and it has a prefix deriveEqual. This prefix is configurable.
package main type MyStruct struct { Int64 int64 StringPtr *string } func (this *MyStruct) Equal(that *MyStruct) bool { return deriveEqual(this, that) }
goderive will then generate the following code in a derived.gen.go file in the same package:
func deriveEqual(this, that *MyStruct) bool { return (this == nil && that == nil) || this != nil && that != nil && this.Int64 == that.Int64 && ((this.StringPtr == nil && that.StringPtr == nil) || (this.StringPtr != nil && that.StringPtr != nil && *(this.StringPtr) == *(that.StringPtr))) }
Supported types:
- basic types
- named structs
- slices
- maps
- pointers to these types
- private fields of structs in external packages (using reflect and unsafe)
- and many more
Unsupported types:
- chan
- interface
- function
- unnamed structs, which are not comparable with the == operator
Example output can be found here: https://github.com/awalterschulze/goderive/tree/master/example/plugin/equal
This plugin has been tested thoroughly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.