What is a good way to test list of variables to see if any are equal to a specific value?
I have a function that loops through a CSV file looking for specific field names and captured the index of the field for later data collection.
Unfortunately, the organization (not mine) that creates the csv file is prone to randomly add field or move the data to a different column, but the column names are consistent.
To help detect if they changed a field name or omitted it altogether, what I want to do is set the field index to -1 and then use something like Python's "any()" function to say if any of (list of variables) = -1 after parsing the header row, then log the error and quit :) .
what would be a good way to implement this in Go?
var (
firstIndex int = -1
secondIndex int = -1
)
for {} // loop checks all of the headers and sets index to the index value.
//psuedo code
check the value of each index variable. if any equal negative one, return error.
I hope that this makes sense. My thought is that I could put the indexes into a map , slice, struct, etc to make looping easier. but I'm still pretty new to Go. And no, I haven't asked AI yet, but that is a good idea!
Ideas?