I have an array like this, which will the response from the API.
[
{
"id": "F1eOrsr3g7gad6",
"created_at": 1591951315,
"url": "https://example.com",
"secret": "1234",
"secret_exists": true
},
{
"id": "FintcvTBaYwPz2",
"created_at": 1591953315,
"url": "http://example.com",
"secret": "34532",
"secret_exists": true
}
]
How do I check this array has the value "F1eOrsr3g7gad6" or not?
I had tried to write a function that will return the index value if the value exists.
func isExists(key string, value string, data []map[string]interface{}) (result int) {
result = -1
for i, search := range data {
if search[key] == value {
result = i
break
}
}
return result
}
var value string = "FintcvTBaYwPz2"
var key string = "id"
result := isExists(key, value, data) // here data will be the array which I want to pass.
fmt.Println("Result: ", result)