Inbuilt method for element wise comparison of 2 struct arrays in Go?

Issue

I have a struct with the below structure,

//Number A struct that represents a new number to be addeded
type Number struct {
    Country   string `json:"country"`
    Number    string `json:"number"`
    CreatedAt string `json:"created_at"`
}

and I a getting a response array of this struct from the REST call and I need to do an element-wise comparison. Is there any inbuilt method to do the same or more efficient way to do it instead of using a for loop and iterating through the elements?

Solution

Is there any inbuilt method to do the same or more efficient way to do it instead of using a for loop and iterating through the elements?

Values of type Number can be compared with == directly.

Answered By – Volker

Answer Checked By – Marilyn (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.