My new course Building a Production-Ready Service in Go is almost complete - try it out and let me know what you think!

Comparing 2 Structs in Go Image Comparing 2 Structs in Go

In this code snippet, we are going to look at how you can compare two structs in Go to see if they are equal.

We’ll be creating a simple Developer struct which will feature a Name and Age field.

In the body of our main function, we’ll define two instances of this struct called elliot and elliot2 - not the most imaginative I know…

Below this, we’ll then use the reflect package from the Go standard library in order to perform a DeepEqual comparison.

Further Reading

If you found this code snippet useful, you may also be interested in some of the other content on the site: